com.expleague.ml.io.FuncEnsembleConversionPack Maven / Gradle / Ivy
package com.expleague.ml.io;
import com.expleague.commons.func.Computable;
import com.expleague.commons.func.types.ConversionPack;
import com.expleague.commons.math.Func;
import com.expleague.commons.math.Trans;
import com.expleague.commons.math.vectors.Vec;
import com.expleague.ml.func.FuncEnsemble;
import com.expleague.commons.util.ArrayTools;
import com.expleague.commons.util.Pair;
/**
* User: qdeee
* Date: 07.04.15
*/
public class FuncEnsembleConversionPack implements ConversionPack {
public static class To extends EnsembleModelConversionPack.BaseTo {
@Override
public CharSequence convert(final FuncEnsemble from) {
return convertModels(from);
}
}
public static class From extends EnsembleModelConversionPack.BaseFrom {
@Override
public FuncEnsemble convert(final CharSequence from) {
final Pair pair = convertModels(from);
final Trans[] models = pair.getFirst();
final Func[] funcModels = ArrayTools.map(models, Func.class, new Computable() {
@Override
public Func compute(final Trans argument) {
return (Func) argument;
}
});
final Vec weights = pair.getSecond();
return new FuncEnsemble(funcModels, weights);
}
}
@Override
public Class to() {
return To.class;
}
@Override
public Class from() {
return From.class;
}
}