List of usage examples for org.apache.commons.math3.optim InitialGuess InitialGuess
public InitialGuess(double[] startPoint)
From source file:com.wwidesigner.optimization.ObjectiveFunctionOptimizer.java
protected static PointValuePair runDirect(MultivariateOptimizer optimizer, BaseObjectiveFunction objective, double[] startPoint) throws TooManyEvaluationsException { PointValuePair outcome;//from w ww . ja v a2 s . c o m // Run optimization first with the first-stage evaluator, if // specified EvaluatorInterface originalEvaluator = objective.getEvaluator(); if (objective.isRunTwoStageOptimization()) { objective.setEvaluator(objective.getFirstStageEvaluator()); } // Specify a target function value, to guard against // underconstrained // optimizations. Value here should be suitable for // CentsDeviationEvaluator, // and adequate for most other evaluators. outcome = optimizer.optimize(GoalType.MINIMIZE, new ObjectiveFunction(objective), new MaxEval(2 * objective.getMaxEvaluations()), MaxIter.unlimited(), new InitialGuess(startPoint), new DIRECTOptimizer.TargetFunctionValue(0.001), new SimpleBounds(objective.getLowerBounds(), objective.getUpperBounds())); objective.setEvaluator(originalEvaluator); return outcome; }
From source file:com.itemanalysis.psychometrics.irt.equating.StockingLordMethodTest.java
/** * Item parameters and "true" linking coefficients are from example2 in Kolen's STUIRT program. * *//*w w w .j av a 2s .co m*/ @Test public void stockingLordTestMixedFormatPARSCALE() { System.out.println("StockingLordMethod Test 4: STUIRT example 2 with PARSCALE parameters"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //Form X irmX.put("v1", new Irm3PL(0.751335, -0.897391, 0.244001, 1.7)); irmX.put("v2", new Irm3PL(0.955947, -0.811477, 0.242883, 1.7)); irmX.put("v3", new Irm3PL(0.497206, -0.858681, 0.260893, 1.7)); irmX.put("v4", new Irm3PL(0.724000, -0.123911, 0.243497, 1.7)); irmX.put("v5", new Irm3PL(0.865200, 0.205889, 0.319135, 1.7)); irmX.put("v6", new Irm3PL(0.658129, 0.555228, 0.277826, 1.7)); irmX.put("v7", new Irm3PL(1.082118, 0.950549, 0.157979, 1.7)); irmX.put("v8", new Irm3PL(0.988294, 1.377501, 0.084828, 1.7)); irmX.put("v9", new Irm3PL(1.248923, 1.614355, 0.181874, 1.7)); irmX.put("v10", new Irm3PL(1.116682, 2.353932, 0.246856, 1.7)); irmX.put("v11", new Irm3PL(0.438171, 3.217965, 0.309243, 1.7)); irmX.put("v12", new Irm3PL(1.082206, 4.441864, 0.192339, 1.7)); double[] step1 = { 1.097268, -1.097268 }; irmX.put("v13", new IrmGPCM2(0.269994, 0.003998, step1, 1.7)); double[] step2 = { 0.106514, -0.106514 }; irmX.put("v14", new IrmGPCM2(0.972506, 1.632662, step2, 1.7)); double[] step3 = { 2.102301, -2.102301 }; irmX.put("v15", new IrmGPCM2(0.378812, 3.464657, step3, 1.7)); double[] step4 = { -0.476513, 1.081282, -0.604770 }; irmX.put("v16", new IrmGPCM2(0.537706, 1.010053, step4, 1.7)); double[] step5 = { 1.007525, -0.197767, -0.809758 }; irmX.put("v17", new IrmGPCM2(0.554506, 2.432938, step5, 1.7)); //Form Y irmY.put("v1", new Irm3PL(0.887276, -1.334798, 0.134406, 1.7)); irmY.put("v2", new Irm3PL(1.184412, -1.129004, 0.237765, 1.7)); irmY.put("v3", new Irm3PL(0.609412, -1.464546, 0.151393, 1.7)); irmY.put("v4", new Irm3PL(0.923812, -0.576435, 0.240097, 1.7)); irmY.put("v5", new Irm3PL(0.822776, -0.476357, 0.192369, 1.7)); irmY.put("v6", new Irm3PL(0.707818, -0.235189, 0.189557, 1.7)); irmY.put("v7", new Irm3PL(1.306976, 0.242986, 0.165553, 1.7)); irmY.put("v8", new Irm3PL(1.295471, 0.598029, 0.090557, 1.7)); irmY.put("v9", new Irm3PL(1.366841, 0.923206, 0.172993, 1.7)); irmY.put("v10", new Irm3PL(1.389624, 1.380666, 0.238008, 1.7)); irmY.put("v11", new Irm3PL(0.293806, 2.028070, 0.203448, 1.7)); irmY.put("v12", new Irm3PL(0.885347, 3.152928, 0.195473, 1.7)); double[] step1Y = { 0.893232, -0.893232 }; irmY.put("v13", new IrmGPCM2(0.346324, -0.494115, step1Y, 1.7)); double[] step2Y = { 0.099750, -0.099750 }; irmY.put("v14", new IrmGPCM2(1.252012, 0.856264, step2Y, 1.7)); double[] step3Y = { 1.850498, -1.850498 }; irmY.put("v15", new IrmGPCM2(0.392282, 2.825801, step3Y, 1.7)); double[] step4Y = { -0.300428, 0.761846, -0.461417 }; irmY.put("v16", new IrmGPCM2(0.660841, 0.342977, step4Y, 1.7)); double[] step5Y = { 1.001974, -0.107221, -0.894753 }; irmY.put("v17", new IrmGPCM2(0.669612, 1.643267, step5Y, 1.7)); UniformDistributionApproximation uniform = new UniformDistributionApproximation(-3.0, 3.0, 25); StockingLordMethod sl = new StockingLordMethod(irmX, irmY, uniform, uniform, EquatingCriterionType.Q1Q2); sl.setPrecision(6); double[] startValues = { 0, 1 }; int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, 10, generator); PointValuePair optimum = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(sl), GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); double[] slCoefficients = optimum.getPoint(); sl.setIntercept(slCoefficients[0]); sl.setScale(slCoefficients[1]); System.out.println(" Iterations: " + optimizer.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + slCoefficients[0] + " A = " + slCoefficients[1]); assertEquals(" Intercept test", -0.456487, sl.getIntercept(), 1e-6); assertEquals(" Scale test", 0.815445, sl.getScale(), 1e-6); System.out.println(); }
From source file:edu.cmu.tetrad.sem.GeneralizedSemIm.java
public DataSet simulateDataMinimizeSurface(int sampleSize, boolean latentDataSaved) { final Map<String, Double> variableValues = new HashMap<String, Double>(); final double func_tolerance = 1.0e-4; final double param_tolerance = 1.0e-3; List<Node> continuousVariables = new LinkedList<Node>(); final List<Node> variableNodes = pm.getVariableNodes(); // Work with a copy of the variables, because their type can be set externally. for (Node node : variableNodes) { ContinuousVariable var = new ContinuousVariable(node.getName()); var.setNodeType(node.getNodeType()); if (var.getNodeType() != NodeType.ERROR) { continuousVariables.add(var); }/* w w w. j av a 2 s . c o m*/ } DataSet fullDataSet = new ColtDataSet(sampleSize, continuousVariables); final Context context = new Context() { public Double getValue(String term) { Double value = parameterValues.get(term); if (value != null) { return value; } value = variableValues.get(term); if (value != null) { return value; } throw new IllegalArgumentException("No value recorded for '" + term + "'"); } }; final double[] _metric = new double[1]; MultivariateFunction function = new MultivariateFunction() { double metric; public double value(double[] doubles) { for (int i = 0; i < variableNodes.size(); i++) { variableValues.put(variableNodes.get(i).getName(), doubles[i]); } double[] image = new double[doubles.length]; for (int i = 0; i < variableNodes.size(); i++) { Node node = variableNodes.get(i); Expression expression = pm.getNodeExpression(node); image[i] = expression.evaluate(context); if (Double.isNaN(image[i])) { throw new IllegalArgumentException("Undefined value for expression " + expression); } } metric = 0.0; for (int i = 0; i < variableNodes.size(); i++) { double diff = doubles[i] - image[i]; metric += diff * diff; } for (int i = 0; i < variableNodes.size(); i++) { variableValues.put(variableNodes.get(i).getName(), image[i]); } _metric[0] = metric; return metric; } }; MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7); // Do the simulation. ROW: for (int row = 0; row < sampleSize; row++) { // Take random draws from error distributions. for (int i = 0; i < variableNodes.size(); i++) { Node variable = variableNodes.get(i); Node error = pm.getErrorNode(variable); Expression expression = pm.getNodeExpression(error); double value = expression.evaluate(context); if (Double.isNaN(value)) { throw new IllegalArgumentException("Undefined value for expression: " + expression); } variableValues.put(error.getName(), value); } for (int i = 0; i < variableNodes.size(); i++) { Node variable = variableNodes.get(i); variableValues.put(variable.getName(), 0.0);// RandomUtil.getInstance().nextUniform(-5, 5)); } while (true) { double[] values = new double[variableNodes.size()]; for (int i = 0; i < values.length; i++) { values[i] = variableValues.get(variableNodes.get(i).getName()); } PointValuePair pair = search.optimize(new InitialGuess(values), new ObjectiveFunction(function), GoalType.MINIMIZE, new MaxEval(100000)); values = pair.getPoint(); for (int i = 0; i < variableNodes.size(); i++) { if (isSimulatePositiveDataOnly() && values[i] < 0) { row--; continue ROW; } if (!Double.isNaN(selfLoopCoef) && row > 0) { values[i] += selfLoopCoef * fullDataSet.getDouble(row - 1, i); } variableValues.put(variableNodes.get(i).getName(), values[i]); fullDataSet.setDouble(row, i, values[i]); } if (_metric[0] < 0.01) { break; // while } } } if (latentDataSaved) { return fullDataSet; } else { return DataUtils.restrictToMeasured(fullDataSet); } }
From source file:com.itemanalysis.psychometrics.irt.equating.HaebaraMethodTest.java
@Test public void haebaraMethodTestMixedFormat2() { System.out.println("HaebaraMethod Test 4: Mixed format test, symmetric, PARSCALE parameters"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //Form X//from w w w . j ava 2s.c om irmX.put("v1", new Irm3PL(0.751335, -0.897391, 0.244001, 1.7)); irmX.put("v2", new Irm3PL(0.955947, -0.811477, 0.242883, 1.7)); irmX.put("v3", new Irm3PL(0.497206, -0.858681, 0.260893, 1.7)); irmX.put("v4", new Irm3PL(0.724000, -0.123911, 0.243497, 1.7)); irmX.put("v5", new Irm3PL(0.865200, 0.205889, 0.319135, 1.7)); irmX.put("v6", new Irm3PL(0.658129, 0.555228, 0.277826, 1.7)); irmX.put("v7", new Irm3PL(1.082118, 0.950549, 0.157979, 1.7)); irmX.put("v8", new Irm3PL(0.988294, 1.377501, 0.084828, 1.7)); irmX.put("v9", new Irm3PL(1.248923, 1.614355, 0.181874, 1.7)); irmX.put("v10", new Irm3PL(1.116682, 2.353932, 0.246856, 1.7)); irmX.put("v11", new Irm3PL(0.438171, 3.217965, 0.309243, 1.7)); irmX.put("v12", new Irm3PL(1.082206, 4.441864, 0.192339, 1.7)); double[] step1 = { 1.097268, -1.097268 }; irmX.put("v13", new IrmGPCM2(0.269994, 0.003998, step1, 1.7)); double[] step2 = { 0.106514, -0.106514 }; irmX.put("v14", new IrmGPCM2(0.972506, 1.632662, step2, 1.7)); double[] step3 = { 2.102301, -2.102301 }; irmX.put("v15", new IrmGPCM2(0.378812, 3.464657, step3, 1.7)); double[] step4 = { -0.476513, 1.081282, -0.604770 }; irmX.put("v16", new IrmGPCM2(0.537706, 1.010053, step4, 1.7)); double[] step5 = { 1.007525, -0.197767, -0.809758 }; irmX.put("v17", new IrmGPCM2(0.554506, 2.432938, step5, 1.7)); //Form Y irmY.put("v1", new Irm3PL(0.887276, -1.334798, 0.134406, 1.7)); irmY.put("v2", new Irm3PL(1.184412, -1.129004, 0.237765, 1.7)); irmY.put("v3", new Irm3PL(0.609412, -1.464546, 0.151393, 1.7)); irmY.put("v4", new Irm3PL(0.923812, -0.576435, 0.240097, 1.7)); irmY.put("v5", new Irm3PL(0.822776, -0.476357, 0.192369, 1.7)); irmY.put("v6", new Irm3PL(0.707818, -0.235189, 0.189557, 1.7)); irmY.put("v7", new Irm3PL(1.306976, 0.242986, 0.165553, 1.7)); irmY.put("v8", new Irm3PL(1.295471, 0.598029, 0.090557, 1.7)); irmY.put("v9", new Irm3PL(1.366841, 0.923206, 0.172993, 1.7)); irmY.put("v10", new Irm3PL(1.389624, 1.380666, 0.238008, 1.7)); irmY.put("v11", new Irm3PL(0.293806, 2.028070, 0.203448, 1.7)); irmY.put("v12", new Irm3PL(0.885347, 3.152928, 0.195473, 1.7)); double[] step1Y = { 0.893232, -0.893232 }; irmY.put("v13", new IrmGPCM2(0.346324, -0.494115, step1Y, 1.7)); double[] step2Y = { 0.099750, -0.099750 }; irmY.put("v14", new IrmGPCM2(1.252012, 0.856264, step2Y, 1.7)); double[] step3Y = { 1.850498, -1.850498 }; irmY.put("v15", new IrmGPCM2(0.392282, 2.825801, step3Y, 1.7)); double[] step4Y = { -0.300428, 0.761846, -0.461417 }; irmY.put("v16", new IrmGPCM2(0.660841, 0.342977, step4Y, 1.7)); double[] step5Y = { 1.001974, -0.107221, -0.894753 }; irmY.put("v17", new IrmGPCM2(0.669612, 1.643267, step5Y, 1.7)); UniformDistributionApproximation uniform = new UniformDistributionApproximation(-3.0, 3.0, 25); HaebaraMethod hb = new HaebaraMethod(irmX, irmY, uniform, uniform, EquatingCriterionType.Q1Q2); hb.setPrecision(4); double[] startValues = { 0, 1 }; int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, 10, generator); org.apache.commons.math3.optim.PointValuePair optimum = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(hb), org.apache.commons.math3.optim.nonlinear.scalar.GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); double[] hbCoefficients = optimum.getPoint(); hb.setIntercept(hbCoefficients[0]); hb.setScale(hbCoefficients[1]); System.out.println(" Iterations: " + optimizer.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + hbCoefficients[0] + " A = " + hbCoefficients[1]); assertEquals(" Intercept test", -0.446101, hb.getIntercept(), 1e-4); assertEquals(" Scale test", 0.805049, hb.getScale(), 1e-4); System.out.println(); }
From source file:com.itemanalysis.psychometrics.irt.equating.HaebaraMethodTest.java
@Test public void haebaraMethodTestMixedFormat3() { System.out.println("HaebaraMethod Test 5: Mixed format test, symmetric, Graded Response"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //3pl items/*from w w w . java2 s. co m*/ irmX.put("v1", new Irm3PL(1.0755, -1.8758, 0.1240, 1.7)); irmX.put("v2", new Irm3PL(0.6428, -0.9211, 0.1361, 1.7)); irmX.put("v3", new Irm3PL(0.6198, -1.3362, 0.1276, 1.7)); irmX.put("v4", new Irm3PL(0.6835, -1.8967, 0.1619, 1.7)); irmX.put("v5", new Irm3PL(0.9892, -0.6427, 0.2050, 1.7)); irmX.put("v6", new Irm3PL(0.5784, -0.8181, 0.1168, 1.7)); irmX.put("v7", new Irm3PL(0.9822, -0.9897, 0.1053, 1.7)); irmX.put("v8", new Irm3PL(1.6026, -1.2382, 0.1202, 1.7)); irmX.put("v9", new Irm3PL(0.8988, -0.5180, 0.1320, 1.7)); irmX.put("v10", new Irm3PL(1.2525, -0.7164, 0.1493, 1.7)); //gpcm items double[] step1 = { -2.1415, 0.0382, 0.6551 }; irmX.put("v11", new IrmGRM(1.1196, step1, 1.7)); double[] step2 = { -1.7523, -1.0660, 0.3533 }; irmX.put("v12", new IrmGRM(1.2290, step2, 1.7)); double[] step3 = { -2.3126, -1.8816, 0.7757 }; irmX.put("v13", new IrmGRM(0.6405, step3, 1.7)); double[] step4 = { -1.9728, -0.2810, 1.1387 }; irmX.put("v14", new IrmGRM(1.1622, step4, 1.7)); double[] step5 = { -2.2207, -0.8252, 0.9702 }; irmX.put("v15", new IrmGRM(1.2249, step5, 1.7)); //3pl items irmY.put("v1", new Irm3PL(0.7444, -1.5617, 0.1609, 1.7)); irmY.put("v2", new Irm3PL(0.5562, -0.1031, 0.1753, 1.7)); irmY.put("v3", new Irm3PL(0.5262, -1.0676, 0.1602, 1.7)); irmY.put("v4", new Irm3PL(0.6388, -1.3880, 0.1676, 1.7)); irmY.put("v5", new Irm3PL(0.8793, -0.2051, 0.1422, 1.7)); irmY.put("v6", new Irm3PL(0.4105, 0.0555, 0.2120, 1.7)); irmY.put("v7", new Irm3PL(0.7686, -0.3800, 0.2090, 1.7)); irmY.put("v8", new Irm3PL(1.0539, -0.7570, 0.1270, 1.7)); irmY.put("v9", new Irm3PL(0.7400, 0.0667, 0.1543, 1.7)); irmY.put("v10", new Irm3PL(0.7479, 0.0281, 0.1489, 1.7)); //gpcm items double[] step6 = { -1.7786, 0.7177, 1.45011 }; irmY.put("v11", new IrmGRM(0.9171, step6, 1.7)); double[] step7 = { -1.4115, -0.4946, 1.15969 }; irmY.put("v12", new IrmGRM(0.9751, step7, 1.7)); double[] step8 = { -1.8478, -1.4078, 1.51339 }; irmY.put("v13", new IrmGRM(0.5890, step8, 1.7)); double[] step9 = { -1.6151, 0.3002, 2.04728 }; irmY.put("v14", new IrmGRM(0.9804, step9, 1.7)); double[] step10 = { -1.9355, -0.2267, 1.88991 }; irmY.put("v15", new IrmGRM(1.0117, step10, 1.7)); UniformDistributionApproximation uniform = new UniformDistributionApproximation(-3.0, 3.0, 25); HaebaraMethod hb = new HaebaraMethod(irmX, irmY, uniform, uniform, EquatingCriterionType.Q1Q2); hb.setPrecision(4); double[] startValues = { 0, 1 }; int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, 10, generator); org.apache.commons.math3.optim.PointValuePair optimum = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(hb), org.apache.commons.math3.optim.nonlinear.scalar.GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); double[] hbCoefficients = optimum.getPoint(); hb.setIntercept(hbCoefficients[0]); hb.setScale(hbCoefficients[1]); System.out.println(" Iterations: " + optimizer.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + hbCoefficients[0] + " A = " + hbCoefficients[1]); assertEquals(" Intercept test", 0.715912, hb.getIntercept(), 1e-4); assertEquals(" Scale test", 1.203554, hb.getScale(), 1e-4); System.out.println(); }
From source file:com.itemanalysis.psychometrics.irt.equating.StockingLordMethodTest.java
/** * Item parameter and "true" linking coefficients are based on example 2 in Kolen's STUIRT program. * For polytomous items, the difficulty and threshold parameters were combined to be step parameters * as done with Brad Hanson's GPCM. That is, teh parameters are configured to conform to the "IS" * version of the GPCM as specified in the STUIRT manual. *//* w w w . ja va 2 s .c om*/ @Test public void stockingLordTestMixedICL() { System.out.println("StockingLordMethod Test 4: STUIRT example 2 with ICL parameters"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //Form X irmX.put("v1", new Irm3PL(0.751335, -0.897391, 0.244001, 1.7)); irmX.put("v2", new Irm3PL(0.955947, -0.811477, 0.242883, 1.7)); irmX.put("v3", new Irm3PL(0.497206, -0.858681, 0.260893, 1.7)); irmX.put("v4", new Irm3PL(0.724000, -0.123911, 0.243497, 1.7)); irmX.put("v5", new Irm3PL(0.865200, 0.205889, 0.319135, 1.7)); irmX.put("v6", new Irm3PL(0.658129, 0.555228, 0.277826, 1.7)); irmX.put("v7", new Irm3PL(1.082118, 0.950549, 0.157979, 1.7)); irmX.put("v8", new Irm3PL(0.988294, 1.377501, 0.084828, 1.7)); irmX.put("v9", new Irm3PL(1.248923, 1.614355, 0.181874, 1.7)); irmX.put("v10", new Irm3PL(1.116682, 2.353932, 0.246856, 1.7)); irmX.put("v11", new Irm3PL(0.438171, 3.217965, 0.309243, 1.7)); irmX.put("v12", new Irm3PL(1.082206, 4.441864, 0.192339, 1.7)); double[] step1 = { 0.0, 1.101266, -1.09327 }; irmX.put("v13", new IrmGPCM(0.269994, step1, 1.7)); double[] step2 = { 0.0, 1.739176, 1.526148 }; irmX.put("v14", new IrmGPCM(0.972506, step2, 1.7)); double[] step3 = { 0.0, 5.566958, 1.362356 }; irmX.put("v15", new IrmGPCM(0.378812, step3, 1.7)); double[] step4 = { 0.0, 0.533540, 2.091335, 0.405283 }; irmX.put("v16", new IrmGPCM(0.537706, step4, 1.7)); double[] step5 = { 0.0, 3.440463, 2.235171, 1.62318 }; irmX.put("v17", new IrmGPCM(0.554506, step5, 1.7)); //Form Y irmY.put("v1", new Irm3PL(0.887276, -1.334798, 0.134406, 1.7)); irmY.put("v2", new Irm3PL(1.184412, -1.129004, 0.237765, 1.7)); irmY.put("v3", new Irm3PL(0.609412, -1.464546, 0.151393, 1.7)); irmY.put("v4", new Irm3PL(0.923812, -0.576435, 0.240097, 1.7)); irmY.put("v5", new Irm3PL(0.822776, -0.476357, 0.192369, 1.7)); irmY.put("v6", new Irm3PL(0.707818, -0.235189, 0.189557, 1.7)); irmY.put("v7", new Irm3PL(1.306976, 0.242986, 0.165553, 1.7)); irmY.put("v8", new Irm3PL(1.295471, 0.598029, 0.090557, 1.7)); irmY.put("v9", new Irm3PL(1.366841, 0.923206, 0.172993, 1.7)); irmY.put("v10", new Irm3PL(1.389624, 1.380666, 0.238008, 1.7)); irmY.put("v11", new Irm3PL(0.293806, 2.028070, 0.203448, 1.7)); irmY.put("v12", new Irm3PL(0.885347, 3.152928, 0.195473, 1.7)); double[] step1Y = { 0.0, 0.399117, -1.38735 }; irmY.put("v13", new IrmGPCM(0.346324, step1Y, 1.7)); double[] step2Y = { 0.0, 0.956014, 0.756514 }; irmY.put("v14", new IrmGPCM(1.252012, step2Y, 1.7)); double[] step3Y = { 0.0, 4.676299, 0.975303 }; irmY.put("v15", new IrmGPCM(0.392282, step3Y, 1.7)); double[] step4Y = { 0.0, 0.042549, 1.104823, -0.118440 }; irmY.put("v16", new IrmGPCM(0.660841, step4Y, 1.7)); double[] step5Y = { 0.0, 2.645241, 1.536046, 0.748514 }; irmY.put("v17", new IrmGPCM(0.669612, step5Y, 1.7)); UniformDistributionApproximation uniform = new UniformDistributionApproximation(-3.0, 3.0, 25); StockingLordMethod sl = new StockingLordMethod(irmX, irmY, uniform, uniform, EquatingCriterionType.Q1Q2); sl.setPrecision(6); double[] startValues = { 0, 1 }; //Run test with UNCMIN optimizer DefaultUncminOptimizer optimizer = new DefaultUncminOptimizer(); double[] param1 = null; double[] param2 = null; double f = 0; try { optimizer.minimize(sl, startValues); param1 = optimizer.getParameters(); f = optimizer.getFunctionValue(); sl.setIntercept(param1[0]); sl.setScale(param1[1]); } catch (UncminException ex) { ex.printStackTrace(); } //Check UNCMIN values against results from STUIRT. System.out.println(" UNCMIN Optimization"); System.out.println(" Iterations: "); System.out.println(" fmin: " + f); System.out.println(" B = " + sl.getIntercept() + " A = " + sl.getScale()); assertEquals(" Intercept test", -0.452240, sl.getIntercept(), 1e-6); assertEquals(" Scale test", 0.820927, sl.getScale(), 1e-6); //Check BOBYQA values against STUIRT results. int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer2 = new MultiStartMultivariateOptimizer(underlying, 10, generator); PointValuePair optimum = optimizer2.optimize(new MaxEval(1000), new ObjectiveFunction(sl), GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); param2 = optimum.getPoint(); sl.setIntercept(param2[0]); sl.setScale(param2[1]); System.out.println(); System.out.println(" BOBYQA Optimization"); System.out.println(" Iterations: " + optimizer2.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + param2[0] + " A = " + param2[1]); assertEquals(" Intercept test", -0.452240, sl.getIntercept(), 1e-6); assertEquals(" Scale test", 0.820927, sl.getScale(), 1e-6); //Compare results from each optimizer assertEquals(" Intercept test", param1[0], param2[0], 1e-6); assertEquals(" Scale test", param1[1], param2[1], 1e-6); }
From source file:gdsc.smlm.ij.plugins.pcpalm.PCPALMMolecules.java
private double[] optimiseLeastSquares(float[] x, float[] y, double[] initialSolution) { // Least-squares optimisation using numerical gradients final SkewNormalDifferentiableFunction myFunction = new SkewNormalDifferentiableFunction(initialSolution); myFunction.addData(x, y);// w w w . ja va2 s . c om LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(); PointVectorValuePair optimum = optimizer.optimize(new MaxIter(3000), new MaxEval(Integer.MAX_VALUE), new ModelFunctionJacobian(new MultivariateMatrixFunction() { public double[][] value(double[] point) throws IllegalArgumentException { return myFunction.jacobian(point); } }), new ModelFunction(myFunction), new Target(myFunction.calculateTarget()), new Weight(myFunction.calculateWeights()), new InitialGuess(initialSolution)); double[] skewParameters = optimum.getPoint(); return skewParameters; }
From source file:gdsc.smlm.ij.plugins.pcpalm.PCPALMMolecules.java
private double[] optimiseSimplex(float[] x, float[] y, double[] initialSolution) { // Simplex optimisation SkewNormalMultivariateFunction sn2 = new SkewNormalMultivariateFunction(initialSolution); sn2.addData(x, y);/*from ww w . j a v a2s . c o m*/ NelderMeadSimplex simplex = new NelderMeadSimplex(4); SimplexOptimizer opt = new SimplexOptimizer(1e-6, 1e-10); PointValuePair solution = opt.optimize(new MaxEval(1000), new InitialGuess(initialSolution), simplex, new ObjectiveFunction(sn2), GoalType.MINIMIZE); double[] skewParameters2 = solution.getPointRef(); return skewParameters2; }
From source file:com.itemanalysis.psychometrics.irt.equating.HaebaraMethodTest.java
@Test public void stockingLordTestMixedFormat4() { System.out.println("StockingLordMethod Test 5: Mixed format test, symmetric, Graded Response 2"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //3pl items//from w w w .j av a2s. co m irmX.put("v1", new Irm3PL(1.0755, -1.8758, 0.1240, 1.7)); irmX.put("v2", new Irm3PL(0.6428, -0.9211, 0.1361, 1.7)); irmX.put("v3", new Irm3PL(0.6198, -1.3362, 0.1276, 1.7)); irmX.put("v4", new Irm3PL(0.6835, -1.8967, 0.1619, 1.7)); irmX.put("v5", new Irm3PL(0.9892, -0.6427, 0.2050, 1.7)); irmX.put("v6", new Irm3PL(0.5784, -0.8181, 0.1168, 1.7)); irmX.put("v7", new Irm3PL(0.9822, -0.9897, 0.1053, 1.7)); irmX.put("v8", new Irm3PL(1.6026, -1.2382, 0.1202, 1.7)); irmX.put("v9", new Irm3PL(0.8988, -0.5180, 0.1320, 1.7)); irmX.put("v10", new Irm3PL(1.2525, -0.7164, 0.1493, 1.7)); //gpcm items double[] step1 = { -2.1415, 0.0382, 0.6551 }; irmX.put("v11", new IrmGRM(1.1196, step1, 1.7)); double[] step2 = { -1.7523, -1.0660, 0.3533 }; irmX.put("v12", new IrmGRM(1.2290, step2, 1.7)); double[] step3 = { -2.3126, -1.8816, 0.7757 }; irmX.put("v13", new IrmGRM(0.6405, step3, 1.7)); double[] step4 = { -1.9728, -0.2810, 1.1387 }; irmX.put("v14", new IrmGRM(1.1622, step4, 1.7)); double[] step5 = { -2.2207, -0.8252, 0.9702 }; irmX.put("v15", new IrmGRM(1.2249, step5, 1.7)); //3pl items irmY.put("v1", new Irm3PL(0.7444, -1.5617, 0.1609, 1.7)); irmY.put("v2", new Irm3PL(0.5562, -0.1031, 0.1753, 1.7)); irmY.put("v3", new Irm3PL(0.5262, -1.0676, 0.1602, 1.7)); irmY.put("v4", new Irm3PL(0.6388, -1.3880, 0.1676, 1.7)); irmY.put("v5", new Irm3PL(0.8793, -0.2051, 0.1422, 1.7)); irmY.put("v6", new Irm3PL(0.4105, 0.0555, 0.2120, 1.7)); irmY.put("v7", new Irm3PL(0.7686, -0.3800, 0.2090, 1.7)); irmY.put("v8", new Irm3PL(1.0539, -0.7570, 0.1270, 1.7)); irmY.put("v9", new Irm3PL(0.7400, 0.0667, 0.1543, 1.7)); irmY.put("v10", new Irm3PL(0.7479, 0.0281, 0.1489, 1.7)); //gpcm items double[] step6 = { -1.7786, 0.7177, 1.45011 }; irmY.put("v11", new IrmGRM(0.9171, step6, 1.7)); double[] step7 = { -1.4115, -0.4946, 1.15969 }; irmY.put("v12", new IrmGRM(0.9751, step7, 1.7)); double[] step8 = { -1.8478, -1.4078, 1.51339 }; irmY.put("v13", new IrmGRM(0.5890, step8, 1.7)); double[] step9 = { -1.6151, 0.3002, 2.04728 }; irmY.put("v14", new IrmGRM(0.9804, step9, 1.7)); double[] step10 = { -1.9355, -0.2267, 1.88991 }; irmY.put("v15", new IrmGRM(1.0117, step10, 1.7)); UserSuppliedDistributionApproximation distX = new UserSuppliedDistributionApproximation(points, xDensity); UserSuppliedDistributionApproximation distY = new UserSuppliedDistributionApproximation(points, yDensity); HaebaraMethod hb = new HaebaraMethod(irmX, irmY, distX, distY, EquatingCriterionType.Q1Q2); hb.setPrecision(4); double[] startValues = { 0, 1 }; int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, 10, generator); org.apache.commons.math3.optim.PointValuePair optimum = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(hb), org.apache.commons.math3.optim.nonlinear.scalar.GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); double[] hbCoefficients = optimum.getPoint(); hb.setIntercept(hbCoefficients[0]); hb.setScale(hbCoefficients[1]); System.out.println(" Iterations: " + optimizer.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + hbCoefficients[0] + " A = " + hbCoefficients[1]); assertEquals(" Intercept test", 0.726026, hb.getIntercept(), 1e-4); assertEquals(" Scale test", 1.203780, hb.getScale(), 1e-4); System.out.println(); }
From source file:com.itemanalysis.psychometrics.irt.equating.StockingLordMethodTest.java
@Test public void stockingLordTestMixedFormatGradedResponse() { System.out.println("StockingLordMethod Test 5: Mixed format test, symmetric, Graded Response"); LinkedHashMap<String, ItemResponseModel> irmX = new LinkedHashMap<String, ItemResponseModel>(); LinkedHashMap<String, ItemResponseModel> irmY = new LinkedHashMap<String, ItemResponseModel>(); //3pl items// www.j a va 2 s . c om irmX.put("v1", new Irm3PL(1.0755, -1.8758, 0.1240, 1.7)); irmX.put("v2", new Irm3PL(0.6428, -0.9211, 0.1361, 1.7)); irmX.put("v3", new Irm3PL(0.6198, -1.3362, 0.1276, 1.7)); irmX.put("v4", new Irm3PL(0.6835, -1.8967, 0.1619, 1.7)); irmX.put("v5", new Irm3PL(0.9892, -0.6427, 0.2050, 1.7)); irmX.put("v6", new Irm3PL(0.5784, -0.8181, 0.1168, 1.7)); irmX.put("v7", new Irm3PL(0.9822, -0.9897, 0.1053, 1.7)); irmX.put("v8", new Irm3PL(1.6026, -1.2382, 0.1202, 1.7)); irmX.put("v9", new Irm3PL(0.8988, -0.5180, 0.1320, 1.7)); irmX.put("v10", new Irm3PL(1.2525, -0.7164, 0.1493, 1.7)); //gpcm items double[] step1 = { -2.1415, 0.0382, 0.6551 }; irmX.put("v11", new IrmGRM(1.1196, step1, 1.7)); double[] step2 = { -1.7523, -1.0660, 0.3533 }; irmX.put("v12", new IrmGRM(1.2290, step2, 1.7)); double[] step3 = { -2.3126, -1.8816, 0.7757 }; irmX.put("v13", new IrmGRM(0.6405, step3, 1.7)); double[] step4 = { -1.9728, -0.2810, 1.1387 }; irmX.put("v14", new IrmGRM(1.1622, step4, 1.7)); double[] step5 = { -2.2207, -0.8252, 0.9702 }; irmX.put("v15", new IrmGRM(1.2249, step5, 1.7)); //3pl items irmY.put("v1", new Irm3PL(0.7444, -1.5617, 0.1609, 1.7)); irmY.put("v2", new Irm3PL(0.5562, -0.1031, 0.1753, 1.7)); irmY.put("v3", new Irm3PL(0.5262, -1.0676, 0.1602, 1.7)); irmY.put("v4", new Irm3PL(0.6388, -1.3880, 0.1676, 1.7)); irmY.put("v5", new Irm3PL(0.8793, -0.2051, 0.1422, 1.7)); irmY.put("v6", new Irm3PL(0.4105, 0.0555, 0.2120, 1.7)); irmY.put("v7", new Irm3PL(0.7686, -0.3800, 0.2090, 1.7)); irmY.put("v8", new Irm3PL(1.0539, -0.7570, 0.1270, 1.7)); irmY.put("v9", new Irm3PL(0.7400, 0.0667, 0.1543, 1.7)); irmY.put("v10", new Irm3PL(0.7479, 0.0281, 0.1489, 1.7)); //gpcm items double[] step6 = { -1.7786, 0.7177, 1.45011 }; irmY.put("v11", new IrmGRM(0.9171, step6, 1.7)); double[] step7 = { -1.4115, -0.4946, 1.15969 }; irmY.put("v12", new IrmGRM(0.9751, step7, 1.7)); double[] step8 = { -1.8478, -1.4078, 1.51339 }; irmY.put("v13", new IrmGRM(0.5890, step8, 1.7)); double[] step9 = { -1.6151, 0.3002, 2.04728 }; irmY.put("v14", new IrmGRM(0.9804, step9, 1.7)); double[] step10 = { -1.9355, -0.2267, 1.88991 }; irmY.put("v15", new IrmGRM(1.0117, step10, 1.7)); UniformDistributionApproximation uniform = new UniformDistributionApproximation(-3.0, 3.0, 25); StockingLordMethod sl = new StockingLordMethod(irmX, irmY, uniform, uniform, EquatingCriterionType.Q1Q2); sl.setPrecision(4); double[] startValues = { 0, 1 }; int numIterpolationPoints = 2 * 2;//two dimensions A and B BOBYQAOptimizer underlying = new BOBYQAOptimizer(numIterpolationPoints); RandomGenerator g = new JDKRandomGenerator(); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, 10, generator); PointValuePair optimum = optimizer.optimize(new MaxEval(1000), new ObjectiveFunction(sl), GoalType.MINIMIZE, SimpleBounds.unbounded(2), new InitialGuess(startValues)); double[] slCoefficients = optimum.getPoint(); sl.setIntercept(slCoefficients[0]); sl.setScale(slCoefficients[1]); System.out.println(" Iterations: " + optimizer.getEvaluations()); System.out.println(" fmin: " + optimum.getValue()); System.out.println(" B = " + slCoefficients[0] + " A = " + slCoefficients[1]); assertEquals(" Intercept test", 0.730924, sl.getIntercept(), 1e-4); assertEquals(" Scale test", 1.218034, sl.getScale(), 1e-4); System.out.println(); }