All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.expleague.ml.io.FuncEnsembleConversionPack Maven / Gradle / Ivy

package com.expleague.ml.io;

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;

import java.util.function.Function;

/**
 * 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 Function() {
        @Override
        public Func apply(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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy