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 <bits/stdc++.h> | |
using namespace std; | |
int main() { | |
ios::sync_with_stdio(false); | |
char str[] = "FuYong-Zun"; | |
str[8]='\0'; | |
cout<<str<<endl; | |
string str1 = "FuYong-Zun"; |
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 paintLine(Line *li) { | |
cout<<"PAINT_LINE "<<li -> p1.first <<" "<< li->p1.second <<" " <<li->p2.first<< " "<< li->p2.second<<endl; | |
} | |
void paintSquare(Square* sq) { | |
int x = (sq->top_left.first + sq->bottom_right.first) /2; | |
int y = (sq->top_left.second + sq->bottom_right.second) /2; | |
int len = (sq->bottom_right.first - sq->top_left.first) / 2; | |
cout<<"PAINT_SQUARE "<<x<<" "<<y<<" " << len <<endl; | |
} |
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
% This function returns the attribute with the highest information gain | |
% in the attributes vector. | |
function [best_attribute] = choose_best_decision_attribute(examples, ... | |
attributes, binary_targets) | |
% Create a zero-ed row vector with same dimensions as attributes. | |
gain = zeros(size(attributes, 1), 1); | |
% Calculate information gain for each attribute and store in gain. |
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
% Returns the mode of the binary_targets (either 0 or 1) | |
function [majority_value] = majority_value(binary_targets) | |
majority_value = mode(binary_targets); | |
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
% Given matrix of examples and specified attribute, calculate information | |
% gain of that attribute. | |
function [gain] = information_gain(examples, attribute, binary_targets) | |
% Extracts from example matrix, positive examples where attribute is 1. | |
% Creates a bitmap that represents if the attribute in the row is | |
% either 1 or 0. | |
positive_examples = (examples(:, attribute) == 1); | |
% Won't this mean that positive bitmap size and negative bitmap size |
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
% Entropy = - (P+) log_2 (P+) - (P-) log_2 (P-), | |
% where P+ is proportion of positive examples in example matrix. | |
% where P- is proportion of negative examples in example matrix. | |
% Calculates the entropy given the binary_targets (vector of 0s and 1s) | |
% Examples | |
% entropy([1 1]) => 0 | |
% entropy([1 0]) => 1 | |
function [result] = entropy(binary_targets) |
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
% Main file for creating decision tree. | |
function[tree] = decision_tree(examples_matrix, attributes_vector, ... | |
binary_targets) | |
% tree.op: label for node (empty for leaf node) | |
% tree.kids: cell array which contains subtrees (empty for leaf node) | |
% tree.class: label for leaf node (empty for internal node) | |
% If all of classifications are the same |
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 [net] = create_traingd(x, y, list_num_hidden_neurons, ... | |
num_epochs, train_idx, validation_idx, test_idx, lr) | |
%[x2, y2] = ANNdata(x, y); | |
net = feedforwardnet(list_num_hidden_neurons); | |
net = configure(net, x, y); | |
net.trainFcn = 'traingd'; | |
net.divideFcn = 'divideind'; | |
net.divideParam.trainInd = train_idx; | |
net.divideParam.valInd = validation_idx; | |
net.divideParam.testInd = test_idx; |
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 [results] = f1_measure(matrix) | |
precision = avg_precision_rate(matrix); | |
recall = avg_recall_rate(matrix); | |
dim = size(matrix, 1); | |
results = zeros(1, dim); | |
for i = 1 : dim | |
results(i) = 2 * precision(i) * recall(i) / (precision(i) + recall(i)); | |
end | |
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
% Returns indices for training set and test set | |
% e.g. partition(1) => [1:900 , 901:1004] | |
function [training_idx testing_idx] = partition(ith_partition, x2) | |
nrows = size(x2, 2); | |
test_set_start_index = floor((ith_partition - 1) / 10 * nrows) + 1; | |
test_set_end_index = floor(ith_partition / 10 * nrows); | |
testing_idx = test_set_start_index:test_set_end_index; | |
training_idx = setdiff(1:nrows, testing_idx); | |
end |
NewerOlder