Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2021, Peter Abeles. All Rights Reserved.
*
* This file is part of BoofCV (http://boofcv.org).
*
* 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.
*/
package boofcv.struct;
import boofcv.misc.BoofMiscOps;
import lombok.Getter;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Random;
/**
* Generates configuration. Intended for use in parameter tuning when you wish to sample a grid of values or randomly
* sample possible settings.
*
* Usage:
*
*
Specify which parameters are to be sampled
*
Call {@link #initialize()}
*
Check {@link #hasNext()} to see if there are more configs to generate
*
Call {@link #next()} for a new instance of a config to test
*
*
* @author Peter Abeles
*/
@SuppressWarnings({"unchecked", "NullAway.Init"})
public abstract class ConfigGenerator {
/** Total number of different configurations it will generate */
@Getter int numTrials;
/** Initial seed for the random number generator */
@Getter long seed;
/** What type of {@link Configuration} it will generate */
@Getter Class type;
/** How many configurations have already been generated. */
@Getter int trial;
// random number generator used internally
protected Random rand;
// All the parameters that will have their states sampled
protected List parameters = new ArrayList<>();
/** Base config that's modified when generating new configures */
@Getter protected Config configurationBase;
/** The most recently generated configuration */
protected Config configCurrent;
protected ConfigGenerator( long seed, Class type ) {
this.seed = seed;
this.type = type;
try {
configurationBase = type.getConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* After all the parameters have been set, call this function to finalize internal variables and begin
* the generator. Up until this function is called, any changes in the baseline will be reflected in
* later calls
*/
public void initialize() {
trial = 0;
rand = new Random(seed);
}
/**
* Returns the number of possible states a parameter has
*/
protected int getNumberOfStates( Parameter p ) {
if (p.getStateSize() == 0)
throw new RuntimeException("There are an infinite number of states");
return p.getStateSize();
}
/**
* Assignment state is the set of enum values passed in
*/
public > void setOfEnums( String parameter, Enum... values ) {
checkPath(parameter, values[0].getDeclaringClass());
parameters.add(new SetOfObjects(parameter, BoofMiscOps.asList((Object[])values)));
}
/**
* Assignment state is the finite set of passed in integers
*/
public void setOfIntegers( String parameter, int... values ) {
checkPath(parameter, int.class);
List