Skip to content

Commit 21e1373

Browse files
fix typos and switch to public classes and using abstractions
1 parent 96f7f3e commit 21e1373

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

NLDF/GenDFEx.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
import com.nag.routines.E04.E04GNX; // confun dummy
44
import com.nag.routines.E04.E04GNY; // congrd dummy
55
import com.nag.routines.E04.E04RA; // Handle init
6-
import com.nag.routines.E04.E04RH; //box bounds
6+
import com.nag.routines.E04.E04RH; // box bounds
77
import com.nag.routines.E04.E04RJ; // linear constraints
88
import com.nag.routines.E04.E04RM; // add model and residual sparsity structure
9-
import com.nag.routines.E04.E04RZ; //destroy handle
9+
import com.nag.routines.E04.E04RZ; // destroy handle
1010
import com.nag.routines.E04.E04ZM; // optional parameters
1111

1212
import java.lang.Math;
1313
import java.util.Arrays;
14-
//import java.io.File;
15-
//import java.io.IOException;
16-
///import java.io.FileWriter;
14+
1715

1816
public class GenDFEx {
1917

@@ -36,7 +34,7 @@ public static void main (String[] args) {
3634
double [] ruser1 = toydata1(t); // For Example 1
3735
double [] ruser2 = toydata2(t); // For Example 2
3836

39-
double [] x = new double [2]; // instatiate an array for as many variable you need
37+
double [] x = new double [2]; // instantiate an array for as many variable you need
4038
long handle = 0;
4139
int nvar = x.length;
4240
int ifail;
@@ -55,7 +53,7 @@ public static void main (String[] args) {
5553
e04ra.eval(handle, nvar, ifail);
5654
handle = e04ra.getHANDLE();
5755

58-
// define the residual functions and sparsity structure
56+
// Define the residual functions and sparsity structure
5957
ifail = 0;
6058
e04rm.eval(handle, nres, isparse, nnzrd, irowrd, icolrd, ifail);
6159

@@ -79,7 +77,7 @@ public static void main (String[] args) {
7977
System.out.println("\n----Solving Toy Dataset #1 with L2 Loss Function----");
8078
ifail = 0;
8179
x = init_x(); //give x the initial guess you want to start from
82-
// x will be changed during solve
80+
// NOTE: x will be changed during solve
8381
e04gn.eval(handle, lsqfun, lsqgrd, confun, congrd, monit, nvar, x, nres, rx, rinfo,
8482
stats, iuser, ruser1, cpuser, ifail);
8583

@@ -116,20 +114,20 @@ public static void main (String[] args) {
116114
e04gn.eval(handle, lsqfun, lsqgrd, confun, congrd, monit, nvar, x, nres, rx, rinfo,
117115
stats, iuser, ruser2, cpuser, ifail);
118116

119-
e04rz.eval(handle,ifail); // destroy the handle
117+
e04rz.eval(handle,ifail); // Destroy the handle
120118

121119
}
122120

123121

124-
private static class LSQFUN extends E04GN.Abstract_E04GN_LSQFUN {
122+
public static class LSQFUN extends E04GN.Abstract_E04GN_LSQFUN {
125123
public void eval() {
126124
for(int i = 0; i < NRES; i++){
127125
this.RX[i] = RUSER[NRES + i] - X[0] * Math.sin(X[1] * RUSER[i]);
128126
}
129127
}
130128
}
131129

132-
private static class LSQGRD extends E04GN.Abstract_E04GN_LSQGRD {
130+
public static class LSQGRD extends E04GN.Abstract_E04GN_LSQGRD {
133131
public void eval() {
134132
for(int i = 0; i < NRES; i++){
135133
this.RDX[i * NVAR] = (-1 * Math.sin(X[1]*RUSER[i]));
@@ -139,26 +137,26 @@ public void eval() {
139137
}
140138

141139
// Dummy Functions required for NLDF solver
142-
private static class CONFUN extends E04GNX implements E04GN.E04GN_CONFUN {
140+
public static class CONFUN extends E04GN.Abstract_E04GN_CONFUN {
143141
public void eval(){
144-
super.eval();
142+
this.eval();
145143
}
146144
}
147145

148-
private static class CONGRD extends E04GNY implements E04GN.E04GN_CONGRD {
146+
public static class CONGRD extends E04GN.Abstract_E04GN_CONGRD {
149147
public void eval(){
150-
super.eval();
148+
this.eval();
151149
}
152150
}
153151

154-
private static class MONIT extends E04GNU implements E04GN.E04GN_MONIT {
152+
public static class MONIT extends E04GN.Abstract_E04GN_MONIT {
155153
public void eval(){
156-
super.eval();
154+
this.eval();
157155
}
158156
}
159157

160158
// Utilities for setting up data for problem
161-
private static double[] linspace(double startPoint, double endPoint, int length) {
159+
public static double[] linspace(double startPoint, double endPoint, int length) {
162160
double[] a = new double[length];
163161
double step = (endPoint - startPoint) / (length - 1);
164162
a[0] = startPoint;
@@ -169,7 +167,7 @@ private static double[] linspace(double startPoint, double endPoint, int length)
169167
return a;
170168
}
171169

172-
private static double[] toydata1(double [] t) {
170+
public static double[] toydata1(double [] t) {
173171
double [] y = new double[t.length * 2];
174172
for(int i = 0; i < t.length * 2; i++){
175173
if(i < t.length){
@@ -185,7 +183,7 @@ private static double[] toydata1(double [] t) {
185183
return y;
186184
}
187185

188-
private static double[] toydata2(double [] t) {
186+
public static double[] toydata2(double [] t) {
189187
double [] y = new double[t.length * 2];
190188
for(int i = 0; i < t.length * 2; i++){
191189
if(i < t.length){
@@ -202,7 +200,7 @@ private static double[] toydata2(double [] t) {
202200
}
203201

204202
// For resetting the initial guess
205-
private static double[] init_x() {
203+
public static double[] init_x() {
206204
double [] x = new double [] {2.1,1.4};
207205
return x;
208206
}

0 commit comments

Comments
 (0)