<commit_before>/**
 * Copyright (C) 2010 openecho
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
package openecho.math;

/**
 * Variance-Covariance utility for to generate a variance-covariance matrix (n x n)
 * for a matrix (m x n) of  data.
 *
 * The calculation is based on the following formula,
 *
 * Cov(X, Y) = Σ ( Xi - X ) ( Yi - Y ) / N = Σ xiyi / N
 *
 * This version first calculates the a deviation score matrix,
 *
 * x = X - 11'X ( 1 / n )
 *
 * Then calculates the a covariance matrix using,
 *
 * V = x'x ( 1 / n )
 *
 * @author openecho
 * @version 1.0.0
 */
public class VarianceCovariance {
    public static double[][] evaluate(double[][] data) {
        if(data == null) {
            throw new NullPointerException();
        }
        SimpleMatrix a = new SimpleMatrix(DeviationScore.evaluate(data));
        return SimpleMatrix.transpose(a).multiply(a).divideScalar(a.getM()).getData();
    }
}<commit_msg>Change to use instance transpose method<commit_after>/**
 * Copyright (C) 2010 openecho
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
package openecho.math;

/**
 * Variance-Covariance utility for to generate a variance-covariance matrix (n x n)
 * for a matrix (m x n) of  data.
 *
 * The calculation is based on the following formula,
 *
 * Cov(X, Y) = Σ ( Xi - X ) ( Yi - Y ) / N = Σ xiyi / N
 *
 * This version first calculates the a deviation score matrix,
 *
 * x = X - 11'X ( 1 / n )
 *
 * Then calculates the a covariance matrix using,
 *
 * V = x'x ( 1 / n )
 *
 * @author openecho
 * @version 1.0.0
 */
public class VarianceCovariance {
    public static double[][] evaluate(double[][] data) {
        if(data == null) {
            throw new NullPointerException();
        }
        SimpleMatrix a = new SimpleMatrix(DeviationScore.evaluate(data));
        return a.transpose().multiply(a).divideScalar(a.getM()).getData();
    }
}
{'fraction_non_alphanumeric': 0.10729023383768914, 'fraction_numerical': 0.01031636863823934, 'mean_word_length': 3.051532033426184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654509', 'n_tokens_mistral': 874, 'n_tokens_neox': 830, 'n_words': 347}