Skip to main content

Posts

matlab normalization

Using meand stddev  function [featureIn,meanFeatIn, stdDevFeatIn] = mynorm_train(featureIn) meanFeatIn = mean(featureIn,1); stdDevFeatIn = std(featureIn,1,1); noSample = size(featureIn,1); for i=1:noSample     featureIn(i,:) = (featureIn(i,:) - meanFeatIn) ./ stdDevFeatIn ; end end  function [testFeatureIn] = mynorm_test(testFeatureIn,meanFeatIn,stdDevFeatIn)     noSample = size(testFeatureIn,1);     noInputFeat = size(testFeatureIn,2);     for i=1:noSample             testFeatureIn(i,1:noInputFeat) = (testFeatureIn(i,1:noInputFeat) - meanFeatIn ) ./ stdDevFeatIn;               end   end Using range  function [ N_feature,feature_range,feature_bases ] = normalize( features ) %NORMALIZE Summary of this function goes here %   Detailed explanation go...

matlab feature ranking

used function rankfeatures (consider sample as column) ==================================================== train = [trainFeature trainLabel]; [IDX ,Z] = rankfeatures( trainFeature' , trainLabel' ,' Criterion ', 'ttest' ); % ttest / entropy/ etc... topRankedFeature = (size( trainLabel ,1)) / 2 ; classify( testFeature ( :,IDX(1:topRankedFeature) ) ,   ...           trainFeature( :,IDX(1:topRankedFeature) ) , trainLabel , ...     ' diagquadratic' ) % liner/quadratic/ diagquadratic etc % transpose as it takes sample as column vector % ttest / entropy/ etc...   %IDX is the list of indices to the rows in X with the most significant features.   %Z is the absolute value of the criterion used (see below)

MATLAB check unique string in file

function identifyDuplicate clc; uniqueSeq={}; dupSeq={}; index=1; uniqueIndex=1; dupIndex=1; uniq=[]; dup=[]; isDuplicated = 0; fid = fopen('1400M_from_287PS_287NS.ranked','r'); tline = fgetl(fid); % ******  while ischar(tline)           consensusSeq = fgetl(fid); % Consessus: AAACC      consensusSeq = upper(consensusSeq);      curSeq = sscanf(consensusSeq,'%*s %s', [1, inf]);      curSeq = upper(curSeq);      fgetl(fid); % Threshold      fgetl(fid); % Coverage      fgetl(fid); % p-value      fgetl(fid); % r1      fgetl(fid); % r2      fgetl(fid); % r3      fgetl(fid); % r4           isExist=0;           for en=1:uniqueIndex -1       ...

MATLAB cross validation

// use built-in function samplesize = size( matrix , 1); c = cvpartition(samplesize,  'kfold' , k); % return the indexes on each fold ///// output in matlab console K-fold cross validation partition              N: 10    NumTestSets: 4      TrainSize: 8  7  7  8       TestSize: 2  3  3  2 ////////////////////// for i=1 : k    trainIdxs = find(training(c,i) ); %training(c,i);  // 1 means in train , 0 means in test    testInxs  = find(test(c,i)       ); % test(c,i);       // 1 means in test , 0 means in train    trainMatrix = matrix (  matrix(trainIdxs ), : );    testMatrix  = matrix (  matrix(testIdxs  ), : ); end //// now calculate performance %%  calculate performance of a partiti...

MATLAB confusion matrix

%  test_class  & predicted_class must be same dimension % 'order' - describes the order of label. Here labels are 'g' as positive and 'h' as negative [C,order] = confusionmat( test_class(1: noSampleTest), predicted_class, 'order', ['g' ;'h'] ) tp = C(1,1); fn = C(1,2); fp = C(2,1); tn = C(2,2); sensitivity = tp /( tp + fn ) specificity = tn /( fp + tn ) accuracy = (tp+tn) / (tp+fn+fp+tn) tpr = sensitivity fpr = 1-specificity precision = tp /( tp + fp ) fVal = (2*tpr*precision)/(tpr+precision)