-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrossOverDemoSoftmax.m
79 lines (67 loc) · 2.31 KB
/
CrossOverDemoSoftmax.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
clc
close all
clear all
%seq1 = [1 2 3 7 9 10 5 4 6 8]
%seq2 = [4 3 9 2 1 7 6 10 8 5]
%[result1 result2]=CrossoverAtPoint(seq1, seq2, 5)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('AlexNetFeaturesMelanoma_fc6.mat');
TrainFeatures=trainingFeatures;
TrainLabels=double(trainingLabels');
TestFeatures=(testFeatures);
TestLabels=double(testLabels');
[trainLabelNew, testLabelNew] = label_convert(TrainLabels, TestLabels,2);
net = trainSoftmaxLayer(TrainFeatures,trainLabelNew);
Predict=net(TestFeatures);
actual=testLabelNew;
plotconfusion(actual,Predict);
numcorrect = sum(actual==Predict);
accuracy= mean(numcorrect/379);
matrixA=TrainFeatures;
pt1=randi([1,2000]);
pt2=randi([2000,4096]);
[TwoPtcrossTrain]=MatrixTwoPointCrossOver(matrixA,pt1,pt2);
[OnePtcrossTrain]=MatrixCrossOver(matrixA,pt1);
matrixB=TestFeatures;
pt1=randi([1,2000]);
pt2=randi([2000,4096]);
[TwoPtcrossTest]=MatrixTwoPointCrossOver(matrixB,pt1,pt2);
[OnePtcrossTest]=MatrixCrossOver(matrixB,pt1);
net = trainSoftmaxLayer(OnePtcrossTrain,trainLabelNew);
Predict=net(OnePtcrossTest);
actual=testLabelNew;
plotconfusion(actual,Predict);
numcorrect = sum(actual==Predict);
accuracyTwoPoint =mean( numcorrect/379);
function [Mcross]=MatrixCrossOver(matrixA,point)
[r c]=size(matrixA)
Mcross=zeros(r, c);
%point=3;
for j=1:2:r-1
[result1 result2] = CrossoverAtPoint(matrixA(j,:), matrixA(j+1,:), point);
p=j;
Mcross(p,:)=result1 ;
Mcross(p+1,:)=result2;
%j=j+2;
end
end
function [Mcross]=MatrixTwoPointCrossOver(matrixA,point1,point2)
[r c]=size(matrixA)
Mcross=zeros(r, c);
%point=3;
for j=1:2:r-1
[result1 result2] = CrossoverAtTwoPoint(matrixA(j,:), matrixA(j+1,:), point1,point2);
p=j;
Mcross(p,:)=result1 ;
Mcross(p+1,:)=result2;
%j=j+2;
end
end
function [result1 result2] = CrossoverAtPoint(sequence1, sequence2, point)
result1 = [sequence1(1:point-1), sequence2(point:end)];
result2 = [sequence2(1:point-1), sequence1(point:end)];
end
function [result1 result2] = CrossoverAtTwoPoint(sequence1, sequence2, point1,point2)
result1 = [sequence1(1:point1-1), sequence2(point1:point2-1),sequence1(point2:end)];
result2 = [sequence2(1:point1-1), sequence2(point1:point2-1),sequence2(point2:end)];
end