format compact

p0 = [-1 1 1 1 1 -1 1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 1 -1 1 1 1 1 -1]';

%length(p0)

p1 = [-1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]';

%length(p1)

p2 = [1 -1 -1 -1 -1 -1 1 -1 -1 1 1 1 1 -1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 -1 -1 -1 -1 1]';

%length(p2)

% create my 3

p3 = [-1 -1 -1 -1 -1 -1 1 -1 1 1 -1 1 1 -1 1 1 -1 1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1]';

%length(p3)

p4 = [-1 -1 -1 -1 -1 -1 1 1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 1 1 1 1 1]';

%length(p4)

p5 = [1 1 1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 1 1 1]';

%length(p5)

p6 = [1 1 1 1 1 1 1 -1 1 -1 -1 1 1 -1 1 -1 -1 1 1 -1 1 1 1 1 -1 -1 -1 -1 -1 -1]';

%length(p6)

% end of create my3

% Weight calculation

target = [p0 p1 p2 p3]

pTrans = target'

myWeight = target * pTrans

% test with the weight

testingWeight = p0*p0' + p1*p1' + p2*p2' + p3*p3'

%+ p4* p4'+ p5 * p5' + p6 * p6'

% end of test


fprintf("P0 Matched Count: %d\n", doCalculate(p0, myWeight, 2))

fprintf("P1 Matched Count: %d\n", doCalculate(p1, myWeight, 2))

fprintf("p2 Matched Count: %d\n", doCalculate(p2, myWeight, 2))

fprintf("p3 Matched Count: %d\n", doCalculate(p3, myWeight, 2))

%fprintf("p4 Matched Count: %d\n", doCalculate(p4, myWeight, 6))

%fprintf("p5 Matched Count: %d\n", doCalculate(p5, myWeight, 6))

%fprintf("p6 Matched Count: %d\n", doCalculate(p6, myWeight, 6))


function count = doCalculate(inputPx, weight, numberOfPixelChange)

    % inputPx is already transposed

    pxSummation = weight * inputPx;

    pxAxion = hardlims(pxSummation);

    % set up for iteration and change pixel

    counter = 0;

    tempPx = inputPx;

    for i = 1:10

        %fprintf("Start the iteration: %d\n", i);

        for j = 1:numberOfPixelChange

            % change the pixel

            %fprintf("Change Pixel: %d\n", j);

            randomPixel = randi(30);

            if tempPx(randomPixel) == 1

                tempPx(randomPixel)= -1;

            else

                tempPx(randomPixel) = 1;

            end

        end

        tempSummation = weight * tempPx;

        tempAxion = hardlims(tempSummation);

        if pxAxion == tempAxion

            counter = counter + 1;

        end

        % reset the tempPx to original

        tempPx = inputPx;

    end

    count = counter;

end


시발 다 수학임 ㅋㅋㅋ