Convert a C code to Java code of an Artificial Neural Network Problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Convert a C code to Java code of an Artificial Neural Network Problem

Hybrid View

  1. #1
    Join Date
    Aug 2013
    Posts
    1

    Convert a C code to Java code of an Artificial Neural Network Problem

    //Analysis Type - Regression
    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>


    double input_hidden_weights[4][3]=
    {
    {5.52706412733837e-001, 1.28925457193726e-001, 5.63971493109330e-001 },
    {-1.71178004644907e+000, -1.52596666072101e+000, -5.00996881686563e+000 },
    {1.84805441095260e+000, 4.14664704403166e-001, -6.31190329919085e-001 },
    {-5.75580725064369e+000, -5.88786472164176e+000, 6.55702460354330e-001 }
    };

    double hidden_bias[4]={ -1.22139719299858e+000, 2.91772593533840e+000, -9.05733899543194e-001, 3.30978537834433e+000 };

    double hidden_output_wts[1][4]=
    {
    {-2.70667050304236e-001, 8.34208850112333e-001, 8.38407685534142e-002, -8.46927424254966e-001 }
    };

    double output_bias[1]={ 3.27855408071900e-001 };

    double max_input[3]={ 8.00000000000000e+001, 7.90000000000000e+001, 8.40000000000000e+001 };

    double min_input[3]={ 2.50000000000000e+001, 2.50000000000000e+001, 2.30000000000000e+001 };

    double max_target[1]={ 2.10000000000000e+000 };

    double min_target[1]={ 1.00000000000000e+000 };

    double input[3];
    double hidden[4];
    double output[1];

    void ScaleInputs(double* input, double minimum, double maximum, int size)
    {
    double delta;
    long i;
    for(i=0; i<size; i++)
    {
    delta = (maximum-minimum)/(max_input[i]-min_input[i]);
    input[i] = minimum - delta*min_input[i]+ delta*input[i];
    }
    }

    void UnscaleTargets(double* output, double minimum, double maximum, int size)
    {
    double delta;
    long i;
    for(i=0; i<size; i++)
    {
    delta = (maximum-minimum)/(max_target[i]-min_target[i]);
    output[i] = (output[i] - minimum + delta*min_target[i])/delta;
    }
    }

    void ComputeFeedForwardSignals(double* MAT_INOUT,double* V_IN,double* V_OUT, double* V_BIAS,int size1,int size2,int layer)
    {
    int row,col;
    for(row=0;row < size2; row++)
    {
    V_OUT[row]=0.0;
    for(col=0;col<size1;col++)V_OUT[row]+=(*(MAT_INOUT+(row*size1)+col)*V_IN[col]);
    V_OUT[row]+=V_BIAS[row];
    if(layer==0) V_OUT[row] = tanh(V_OUT[row]);
    }
    }

    void RunNeuralNet_Regression ()
    {
    ComputeFeedForwardSignals((double*)input_hidden_weights,input,hidden,hidden_bias,3, 4,0);
    ComputeFeedForwardSignals((double*)hidden_output_wts,hidden,output,output_bias,4, 1,1);
    }

    int main()
    {
    int i=0;
    int keyin=1;
    while(1)
    {
    printf("\nEnter values for Continuous inputs\n");
    printf("Cont. Input-0(Var1): ");
    scanf("%lg",&input[0]);
    printf("Cont. Input-1(Var2): ");
    scanf("%lg",&input[1]);
    printf("Cont. Input-2(Var3): ");
    scanf("%lg",&input[2]);
    ScaleInputs(input,0,1,3);
    RunNeuralNet_Regression();
    UnscaleTargets(output,0,1,1);
    printf("\nPredicted Output of Var4 = %.14e",output[0]);
    printf("\n\nPress any key to make another prediction or enter 0 to quit the program.\n");
    keyin=getch();
    if(keyin==48)break;
    }
    return 0;
    }

  2. #2
    Join Date
    Aug 2013
    Posts
    55

    Re: Convert a C code to Java code of an Artificial Neural Network Problem

    There are C/C++ to Java converters available both free and commersial. Just search the net.

    You could also engage a consulting firm to do your work for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center