package de.lmu.ifi.dbs.elki.data.projection;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
Copyright (C) 2012
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
import de.lmu.ifi.dbs.elki.data.NumberVector;
import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation;
import de.lmu.ifi.dbs.elki.data.type.TypeInformation;
import de.lmu.ifi.dbs.elki.data.type.VectorTypeInformation;
import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.ArrayLikeUtil;
import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.NumberArrayAdapter;
import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.SubsetArrayAdapter;
/**
* Projection class for number vectors.
*
* @author Erich Schubert
*
* @param Vector type
* @param Number type
*/
public class NumericalFeatureSelection, N extends Number> extends AbstractFeatureSelection {
/**
* Minimum dimensionality required for projection
*/
private int mindim;
/**
* Object factory
*/
private V factory;
/**
* Output dimensionality
*/
private int dimensionality;
/**
* Constructor.
*
* @param dims Dimensions
* @param factory Object factory
*/
public NumericalFeatureSelection(int[] dims, V factory) {
super(new SubsetArrayAdapter(getAdapter(factory), dims));
this.factory = factory;
this.dimensionality = dims.length;
int mindim = 0;
for(int dim : dims) {
mindim = Math.max(mindim, dim + 1);
}
this.mindim = mindim;
}
/**
* Choose the best adapter for this.
*
* @param factory Object factory, for type inference
* @return Adapter
*/
private static , N extends Number> NumberArrayAdapter getAdapter(V factory) {
return ArrayLikeUtil.numberVectorAdapter(factory);
}
@SuppressWarnings("unchecked")
@Override
public V project(V data) {
return factory.newNumberVector(data, (NumberArrayAdapter) adapter);
}
@Override
public SimpleTypeInformation getOutputDataTypeInformation() {
@SuppressWarnings("unchecked")
final Class cls = (Class) factory.getClass();
return new VectorTypeInformation(cls, dimensionality, dimensionality);
}
@Override
public TypeInformation getInputDataTypeInformation() {
@SuppressWarnings("unchecked")
final Class cls = (Class) factory.getClass();
return new VectorTypeInformation(cls, mindim, Integer.MAX_VALUE);
}
}