haifengl / smile

Statistical Machine Intelligence & Learning Engine
https://haifengl.github.io
Other
6.02k stars 1.13k forks source link

Dot product Question #754

Closed nandsmalho closed 8 months ago

nandsmalho commented 1 year ago

Hello! While implementing the Maxent class to train a model for this input data :

 int[] labels = {0, 1, 0, 1, 0, 0, 1, 0, 1, 1};
    int[][] features = {
      {1, 2},
      {2, 3},
      {3, 4},
      {4, 5},
      {5, 6},
      {6, 7},
      {7, 8},
      {8, 9},
      {9, 10},
      {10, 11}
    };

I am getting an issue in the Maxent.dot() method :

private static double dot(int[] x, double[] w) {
        double dot = w[w.length - 1];

        for (int i : x) {
            **dot += w[i];**
        }

        return dot;
    }

I dont know if my input data is of the incorrect format or if there is some other issue.

This is how i am training the model : Maxent model = Maxent.fit(trainingData[0].length, trainingData, trainingLabels);

Using Java8 Using the latest 3.0.2 version of smile Build system - Ubuntu 22.04.3 LTS

Also, what is the parameter 'p' we have to input to fit the model? In the test file, there is something with Protein.p - can you give some more insight into this parameter?

haifengl commented 11 months ago

The data is in wrong format. X should be array of index of non-zero entries.

nandsmalho commented 9 months ago

Okay, resolved it! Thank you