Skip to content
Snippets Groups Projects
Commit f51f6c42 authored by felmer's avatar felmer
Browse files

LMS-1883 FeatureVector extended to carry also vocabulary-based features

SVN: 18932
parent 0b296255
No related branches found
No related tags found
No related merge requests found
package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto;
import java.io.Serializable;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
/**
* Feature vector for one well.
......@@ -15,28 +16,101 @@ public class FeatureVector implements Serializable
private final WellPosition wellPosition;
private final double[] values;
private final boolean[] vocabularyFeatureFlags;
private final String[] vocabularyTerms;
/**
* Creates an instance for the specified well assuming all features are numbers.
*/
public FeatureVector(WellPosition well, double[] values)
{
this(well, values, new boolean[values.length], new String[values.length]);
}
/**
* Creates an instance for the specified well.
*
* @param values Array with values of numerical features.
* @param vocabularyFeatureFlags Array telling which feature is a numerical one (
* <code>false</code>) or a vocabulary term (<code>true</code>).
* @param vocabularyTerms Array with values of vocabulary-based features.
* @throws IllegalArgumentException if all arrays have not the same length.
*/
public FeatureVector(WellPosition well, double[] values, boolean[] vocabularyFeatureFlags,
String[] vocabularyTerms)
{
this.wellPosition = well;
this.values = values;
this.vocabularyFeatureFlags = vocabularyFeatureFlags;
this.vocabularyTerms = vocabularyTerms;
if (values.length != vocabularyFeatureFlags.length
|| values.length != vocabularyTerms.length)
{
throw new IllegalArgumentException("Array lengths different: " + values.length + " "
+ vocabularyFeatureFlags.length + " " + vocabularyTerms.length);
}
}
/** well position on a plate */
/** Returns the well position on a plate. */
public WellPosition getWellPosition()
{
return wellPosition;
}
/** feature vector values */
/**
* Returns the array of numerical features. If the value is {@link Double#NaN} it means either
* an unknown value of the numerical feature or a vocabulary-based feature.
*/
public double[] getValues()
{
return values;
}
/**
* Return the array of flags specifying the type of feature where <code>true</code> means
* vocabulary-based feature and <code>false</code> numerical feature.
*/
public final boolean[] getVocabularyFeatureFlags()
{
return vocabularyFeatureFlags;
}
/**
* Returns the array of vocabulary-based features. If the value is <code>null</code> it means
* either an unknown value of the vocabulary-base feature or a numerical feature.
*/
public final String[] getVocabularyTerms()
{
return vocabularyTerms;
}
/**
* Returns the feature vector as a list of objects. The list element is either an instance of
* String (vocabulary-based feature), an instance of Double (numerical feature), or
* <code>null</code> if the feature is unknown.
*/
public List<Object> getValueObjects()
{
ArrayList<Object> result = new ArrayList<Object>();
for (int i = 0; i < values.length; i++)
{
if (vocabularyFeatureFlags[i])
{
result.add(vocabularyTerms[i]);
} else
{
double number = values[i];
result.add(Double.isNaN(number) ? null : number);
}
}
return result;
}
@Override
public String toString()
{
return "wellPosition: " + wellPosition + ", values: " + Arrays.toString(values);
return "wellPosition: " + wellPosition + ", values: " + getValueObjects();
}
}
\ No newline at end of file
......@@ -449,22 +449,12 @@ public class DssServiceRpcScreeningTest extends AssertJUnit
}
private void assertFeatureVector(int expectedRowNumber, int expectedColumnNumber,
FeatureVector featureVector, double... expectedValues)
FeatureVector featureVector, Object... expectedValues)
{
assertEquals(expectedRowNumber, featureVector.getWellPosition().getWellRow());
assertEquals(expectedColumnNumber, featureVector.getWellPosition().getWellColumn());
assertEquals(asList(expectedValues), asList(featureVector.getValues()));
}
private List<Double> asList(double[] values)
{
List<Double> list = new ArrayList<Double>();
for (double value : values)
{
list.add(value);
}
return list;
assertEquals(Arrays.asList(expectedValues).toString(), featureVector.getValueObjects().toString());
}
private void prepareGetHomeDatabaseInstance()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment