CLC;
Clear all;
A=xlsread (' C:\Users\d e l l\documents\matlab\problem four\problem-Two.xls ', ' c34:af61 ');
A=size (a,1);
B=size (a,2);
For I=1:b SA (:, i) = (A (:, i)-mean (A (:, i)))/std (A (:, i))
,%%% standard processing
end
Cm=corrcoef (SA);
[V,d]=eig (CM);
For j=1:b
DS (j,1) =d (b+1-j,b+1-j);
End for
i=1:b
DS (i,2) =ds (i,1)/sum (DS (:, 1));
DS (i,3) =sum (DS (1:i,1))/sum (DS (:, 1));
End
t=0.85;
For k=1:b
if DS (k,3) >=t
covariance matrix;
2. Calculate the feature values of S and sort them in ascending order;
3. Select the feature vectors corresponding to the first n feature values to form a transformation matrix E = [E1, E2 ,..., En '];
4. Finally, for each n-dimensional feature vector X can be converted to n-dimensional new feature vector Y:
Y = transpose (E) (X-m)
Finally, I have to do it myself to remember: I did it with Python numpy. If I do it with C, it's okay to look for things. It's too t
.
pinv(X)
Returns the pseudo-inverse B of matrix X.
norm(X , ref)
The ref specifies the type of the matrix or vector to be solved.
cond(X, p)
Returns the condition number of the P-norm of matrix X. If P = 2 corresponds to 2 norm
[v,d]=eig(X)
Calculate the matrix feature value and feature vector. If the equation XV = VD has a non-zero solution, V is the feature vector and D is the feature value.
Matrix Creation
I. Matrix Definition
Example:> A = [1 2 3; 4 5 6; 7 8 9]1. The matrix is enclosed by square brackets []. 2. Elements in the same row of the matrix are separated by spaces or commas. 3. columns and rows are separated by semicolons. 4. Direct input., you can use carriage return to replace 2. assign values to matrix elements 1. assign values to matrix elements separately.
Example:> X (5) = ABS (x (1 ))2. A large matrix can use a small matrix as its element.
Example:> A = [A; 11 12 1
weight vector.Attention:In this case, it is possible to replace A with the eigenvector of the maximum feature root, possibly in order to maximize the amount of information (a) of the original data (not sure ...). )3. Conformance TestingConsistency test, the specific also involves the combination of consistency test.Third, the realization of MATLABHere first search the data, see this code, the code is very clear, here directly posted here.Clc;clear; A=[1 1.2 1.5 1.5;0.833 1 1.2 1.2;0.667 0.833
., 2.])
Merge arrays
Use the vstack and hstack functions in numpy:
The code is as follows:
>>> A = np. ones (2, 2 ))>>> B = np. eye (2)>>> Print np. vstack (a, B ))[[1. 1.][1. 1.][1. 0.][0. 1.]>>> Print np. hstack (a, B ))[[1. 1. 1. 0.][1. 1. 0. 1.]
Check whether the two functions involve the shortest copy problem:
The code is as follows:
>>> C = np. hstack (a, B ))>>> Print c[[1. 1. 1. 0.][1. 1. 0. 1.]>>> A [1, 1] = 5>>> B [1, 1] = 5>>> Print c[[1. 1. 1. 0.][1. 1. 0. 1.]
We can see that the
eigenvectors of P, resulting in XX (k,1), resulting in a projection matrix Z (KXN) of X on K eigenvectors.5. Reconstruct xx with Z and compare with X to calculate the reconstruction error4. MATLAB implementation of PCA[V, E] = Eig (cov (X ')) [E index] = sort (Diag (e), ' descend '); v = V (:, index); Meanx = mean (X ') '; P=v (:, [1:k]) [r,c] = size (X); Y = P ' * (X-repmat (meanx,1,c)); [R,c] = size (Y); XX = P * Y + repmat (Meanx, 1, c);5. PCA mai
1 #import2 3 intMainintargcConst Char*argv[]) {4 @autoreleasepool {5 //Create and set the number of array elements6Nsmutablearray *arr1=[nsmutablearray arraywithcapacity:7];7 //Copying an array8Nsarray *[email protected][@"Mon",@"Tue",@"Wed",@"Thu",@"Fri",@"Sat",@"Sun"];9Nsmutablearray *arr3=[Nsmutablearray arraywitharray:arr2];Ten //add an element to an array One[Arr3 AddObject:@"Eig"]; A //inserts an element according
11111 00000000-01001011----------10101
111111 00000000-01001011----------110101
1111111 00000000-01001 011----------0110101
11111111 00000000-01001011----------10110101 td>
If We wanted we could go further, but there would is no point. Inside of a computer The result of this computation would is assigned to an eight bit variable, so any bits beyond the Eig HTH would be discarded.With the fact
image, (I = 1, 2... c; j = 1, 2 ..., ni), the mean of the class I projection feature vector is, within the projection space, the nearest classification rule is: if the sample y meets:
At the same time, the minimum distance classification rule is: If sample y meets
Just compile it:
Allsamples = []; Global Pathname; Global Y; Global X; Global P; Global Train_num; Global M; Global N; m = 112 ; % Rown = 92 ; % Columntrain_num =200 ; Gt = Zeros (n, n); pathname = ' C: \
-power method. Basically, I can follow this idea to write it down smoothly. I wrote it myselfCodePut it in the idempotence (this is one of the reasons why I later gave up using my own anti-idempotence ). The algorithm I wrote can also be used for exercises, and the matrix with smaller sizes cannot be seen, but it is unreliable to solve large-scale matrices, therefore, this is just a record of your work.
Later, I found that the problem I solved was not to find the feature values of a general la
here:Step 2: Solving by matrix methodWe also see that the wiki finally says that solution with eigendecompositions is the eigenvalue decomposition.Here is a detailed explanation of how it is done.Turn 4 mds ppt (from your own class teacher's ppt):Explaining it is actually very simple:1) constructs a matrix T, and then finds that the T matrix can be calculated entirely from D.2) t this matrix can be decomposed ah, then the inside eigenvalue if greater than or equal to 0, you can open the square
Original: http://www.cnblogs.com/leonwen/p/5158947.html The algorithm is ported by MATLAB (see the previous blog post for details). But the final output is inconsistent with MATLAB, it is found that in the invocation of the internal function Eig to solve eigenvalues and eigenvectors, both eigenvalues are consistent, but the eigenvectors are different.But, theoretically, it makes sense, because eigenvectors are inherently non-unique. The most puzzling
follows:>>> A = np. ones (2, 2 ))>>> B = np. eye (2)>>> Print np. vstack (a, B ))[[1. 1.][1. 1.][1. 0.][0. 1.]>>> Print np. hstack (a, B ))[[1. 1. 1. 0.][1. 1. 0. 1.]
Check whether the two functions involve the shortest copy problem:Copy codeThe Code is as follows:>>> C = np. hstack (a, B ))>>> Print c[[1. 1. 1. 0.][1. 1. 0. 1.]>>> A [1, 1] = 5>>> B [1, 1] = 5>>> Print c[[1. 1. 1. 0.][1. 1. 0. 1.]We can see that the change of elements in a and B does not affect c.
Deep copy Array
The array obje
matrix matrices, and the column represents the feature, where the percentage represents the variance ratio of the number of features required before taking the default to 0.9" "defPCA (datamat,percentage=0.9): #averaging for each column, because the mean value is subtracted from the calculation of the covarianceMeanvals=mean (datamat,axis=0) meanremoved=datamat-meanvals#CoV () Calculating varianceCovmat=cov (meanremoved,rowvar=0)#using the Eig ()
the inner area width of the first matched element (including padding, excluding borders).Here is an example:CSS code block style type="Text/css"> . Div{ width: px ; Height: + px ; background-color: Green ; padding: tenpx ; Border: px solid #009999 ; margin: px ;} style>jquery code block $(function(){ console.log($(‘div‘).width()+‘+‘+$(‘div‘).innerWidth()+‘+‘+$(‘div‘).outerWidth()); var k = $(‘div‘).height()+‘+‘+ $(‘div‘).innerHeight()+‘+‘+$(‘div‘).outerHeight()+
#define NSLOG (FORMAT, ...) fprintf (stderr, "%s\n", [[NSString Stringwithformat:format, # #__VA_ARGS__] utf8string]);#import int main (int argc, const char * argv[]) {@autoreleasepool {Variable groups inherit immutable groups1, create. Set the number of elements to createNsmutablearray *arr=[nsmutablearray Arraywithcapacity:7];2. Add an element to the arrayNsarray *[email protected][@ "Mon", @ "Tue", @ "Wed", @ "Thu", @ "Fri", @ "sat", @ "Sun"];//immutable variable groupNsmutablearray *arr2=[ns
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.