This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function data = invertData(data, class) | |
indices = (data(:, end) == class); | |
data(indices, end) = 1; | |
data(~indices, end) = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function accuracy = WinnerTakesAll(actual, predict, class) | |
[m, n] = size(actual); | |
[maxP, classP] = max(predict, [], 2); | |
accuracy = 100 * sum(actual(:, n) == class(classP)') / m; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function accuracy = ovasvm(data, n) | |
data = shuffleData(data); | |
[train, test] = splitData(data); | |
[trainSet, valSet] = splitData(train); | |
[trainSet, valSet] = scaleData(trainSet, valSet); | |
A = 1:n; | |
C = [2^-10 2^-9 2^-8 2^-7 2^-6 2^-5 2^-4 2^-3 2^-2 2^-1 2^0 2^1 2^2 2^3 2^4 2^5 2^6 2^7 2^8 2^9 2^10]; | |
accuracy = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function data = shuffleData(data) | |
[m, n] = size(data); | |
indices = randperm(m); | |
data = data(indices, :); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [train, test] = splitData(data) | |
[m, n] = size(data); | |
train = []; | |
test = []; | |
nTrain = round(m * 0.7); | |
train = data(1:nTrain, :); | |
test = data(nTrain + 1:m, :); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [train, test] = scaleData(train, test) | |
[row, col] = size(train); | |
normalMax = 1; | |
normalMin = -1; | |
for i=1:(col-1) | |
realMax = max(train(:, i)); | |
realMin = min(train(:, i)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rate = knn(trainSet, testSet, k) | |
m = size(trainSet, 1); | |
n = size(testSet, 1); | |
predict = []; | |
for test=1:n | |
for train=1:m | |
Eulidist(train) = norm(testSet(test, 1:end-1) - trainSet(train, 1:end-1)); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bresenhamLine(int x0, int y0, int x1, int y1) { | |
int dx = abs(x1 - x0); | |
int dy = abs(y1 - y0); | |
int x, y; | |
if (dx >= dy) { | |
int d = 2 * dy - dx; | |
int ds = 2 * dy; | |
int dt = 2 * (dy - dx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ddaLine(float xa, float ya, float xb, float yb) { | |
int dx = xb - xa, dy = yb - ya; | |
int k, steps; | |
float xinc, yinc, x = xa, y = ya; | |
if (abs(dx) > abs(dy)) { | |
steps = abs(dx); | |
} | |
else { | |
steps = abs(dy); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <glut.h> | |
#include <math.h> | |
#include <cmath> | |
int width = 600, height = 600; | |
int xOg = 200, yOg = 200; | |
int xa, ya, xb, yb; | |
void putPixel(int x, int y) { | |
glColor3f(1.0f, 1.0f, 1.0f); |
NewerOlder