pca

package
v0.0.0-...-3dcb34a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Copyright (C) 2024 BITJUNGLE Rune Mathisen

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.

Description: This file contains the NIPALS PCA algorithm and helper functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateVariancePercentages

func CalculateVariancePercentages(eigenvalues []float64) []float64

calculateVariancePercentages calculates the percentage of variance explained by each principal component.

func NIPALS

func NIPALS(X mat.Matrix, numComponents int) (*mat.Dense, *mat.Dense, []float64, error)

NIPALS performs Principal Component Analysis (PCA) using the Non-linear Iterative Partial Least Squares (NIPALS) algorithm.

X: Data matrix to perform PCA on. numComponents: Number of principal components to compute.

Returns the scores matrix (T), loadings matrix (P), and the Eigenvalues.

The NIPALS algorithm:

Step 1: Choose a column vector t as an initial estimate of the first principal component score.

Step 2: Compute the loading vector p as the matrix product of the transpose of t and X, and normalize p to have unit length.

Step 3: Update the score vector t as the matrix product of X and p, and normalize t to have unit length.

Step 4: Check the convergence of t and p by calculating the squared correlation between the old and new values. If the convergence criterion is met, stop the iteration. Otherwise, go back to Step 2.

Step 5: Deflate the data matrix X by subtracting the outer product of t and p from X. This removes the variance captured by the first principal component.

Step 6: Repeat Steps 1 to 5 to find the next principal component using the deflated X. Continue until the desired number of principal components is obtained.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL