io.github.ericmedvet.jgea.problem.classification.ClassificationProblem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jgea.problem Show documentation
Show all versions of jgea.problem Show documentation
Problem (benchmarks and templates) for jgea.
The newest version!
/*-
* ========================LICENSE_START=================================
* jgea-problem
* %%
* Copyright (C) 2018 - 2024 Eric Medvet
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package io.github.ericmedvet.jgea.problem.classification;
import io.github.ericmedvet.jgea.core.order.ParetoDominance;
import io.github.ericmedvet.jgea.core.order.PartialComparator;
import io.github.ericmedvet.jgea.core.problem.ProblemWithValidation;
import io.github.ericmedvet.jgea.problem.DataUtils;
import io.github.ericmedvet.jnb.datastructure.Pair;
import java.util.ArrayList;
import java.util.List;
public class ClassificationProblem>
implements ProblemWithValidation, List> {
// TODO fix this: currently, it enforces just one objective/metric
private static final PartialComparator> COMPARATOR = ParetoDominance.build(Double.class, 1);
private final ClassificationFitness fitnessFunction;
private final ClassificationFitness validationFunction;
private final List> learningData;
private final List> validationData;
public ClassificationProblem(
List> data,
int folds,
int i,
ClassificationFitness.Metric learningMetric,
ClassificationFitness.Metric validationMetric) {
validationData = DataUtils.fold(data, i, folds);
learningData = new ArrayList<>(data);
learningData.removeAll(validationData);
fitnessFunction = new ClassificationFitness<>(learningData, learningMetric);
validationFunction = new ClassificationFitness<>(validationData, validationMetric);
}
public List> getLearningData() {
return learningData;
}
public List> getValidationData() {
return validationData;
}
@Override
public PartialComparator> qualityComparator() {
return COMPARATOR;
}
@Override
public ClassificationFitness qualityFunction() {
return fitnessFunction;
}
@Override
public ClassificationFitness validationQualityFunction() {
return validationFunction;
}
}