Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explanation please on intepreting the results of clsOptDE test? #3

Closed
roschler opened this issue Mar 26, 2016 · 2 comments
Closed

Explanation please on intepreting the results of clsOptDE test? #3

roschler opened this issue Mar 26, 2016 · 2 comments
Assignees
Labels

Comments

@roschler
Copy link

In the SampleVB project there is this code for using clsOptDE, with two Console write-line statements I added:

   'LeastSquaresMethod 最小二乗法
    With Nothing
        Console.WriteLine("------------------------------ BEGIN: DATA.CSV --------------------")

        '評価関数
        Dim objectiveFunction = New clsLeastSquaresMethod()
        If objectiveFunction.Init("..\..\..\_sampledata\data.csv") = False Then
            Return
        End If

        '最小化
        Dim opt As New LibOptimization.Optimization.clsOptDE(objectiveFunction)
        opt.Init()
        LibOptimization.Util.clsUtil.DebugValue(opt)
        While (opt.DoIteration(50) = False)
            LibOptimization.Util.clsUtil.DebugValue(opt, ai_isOutValue:=False)
        End While
        LibOptimization.Util.clsUtil.DebugValue(opt)
        Console.WriteLine("------------------------------ END: DATA.CSV --------------------")
    End With

When I run the program I get:

------------------------------ BEGIN: DATA.CSV --------------------
TargetFunction:clsLeastSquaresMethod Dimension:5
OptimizeMethod:clsOptDE
Eval :59438373.1751817
IterationCount:0
Result :
-0.0158704898822757
-0.381333913044383
4.93756533831767
-4.28593948466842
3.24185321532233

Eval :1429.78513592157
Eval :0.956465983765879
Eval :0.000497619640101209
Eval :3.08647227393116E-07
Eval :1.38365563205351E-10
Eval :1.84394063162285E-13
Eval :1.06744757544432E-16
Eval :4.16369815393116E-20
Eval :2.33202429712711E-23
TargetFunction:clsLeastSquaresMethod Dimension:5
OptimizeMethod:clsOptDE
Eval :3.04300885378471E-24
IterationCount:460
Result :
0.0499999999999999
0.999999999999999
-9.99999999999997
-99.9999999999999
99.9999999999983

------------------------------ END: DATA.CSV --------------------

Can someone tell me how this relates to the data found in data.csv, the data file used with the object function?:

x,y
-20,-1900
-19.8,-1918.02392
-18.8,-1953.08032
-7.2,62.72128
3.8,-359.10232
7.2,-630.78272

I'm trying to figure out how to use clsOptDE with my app, where I need to call a particular function (the "fitness" function in GA terms) that analyzes a particular test vector against my fitness function. My fitness function uses the field values in the test vector to run a test against a data set.

@tomitomi3
Copy link
Owner

I'm sorry. I did not notice your question.
Later answers.

@tomitomi3
Copy link
Owner

tomitomi3 commented May 14, 2016

Please read "clsLeastSquaresMethod.vb".

A purpose of this class is to find a multinomial expression function coefficient.
At first This class read "data.csv" in Init() function. "data.csv" is a point of the following multinomial expression function.

f(x) = a1 x^4 + a2 x^3 - a3 x^2 - a4 x + a5

By the way, the answer is;

a1 = 0.05
a2 = 1
a3 = -10
a4 = -100
a5 = 100

Objective function implements it in F(). This F() calculates a point value and the residual sum of squares of the Objective function.
temp(0) is value of x. temp(1) is value of y.

Public Overrides Function F(x As List(Of Double)) As Double
    Dim sumDiffSquare As Double = 0

    For Each temp In Me.datas
        Dim predict = x(0) * temp(0) ^ 4 + x(1) * temp(0) ^ 3 + x(2) * temp(0) ^ 2 + x(3) * temp(0) + x(4)
        Dim diffSquare = (temp(1) - predict) ^ 2
        sumDiffSquare += diffSquare
    Next

    Return sumDiffSquare
End Function

The answer converged, and an approximate value solution was found .

Result :
0.0499999999999999 -> a1
0.999999999999999 -> a2
-9.99999999999997 -> a3
-99.9999999999999 -> a4
99.9999999999983 -> a5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants