An implementation of the ID3 Decision Tree algorithm in Java from scratch.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

308 lines
10 KiB

__kernel void splitDataSet(__global char *in, __global int *out, const int rowSpan,
const int colSpan, __global char *pat, const int pat_length, __global char* out_char,
__global char* nullChar)
{
const int idx = get_global_id(0);
int start = (idx * rowSpan);
int end = start + rowSpan;
int N = rowSpan;
int M = pat_length;
bool found = false;
char nullCharTemp = nullChar[0];
if(in[start]!=nullCharTemp)
{
for(int k=start;k<end;k++)
{
int j;
/* For current index i, check for pattern match */
for (j = 0; j < M; j++)
{
if (in[k + j] != pat[j])
break;
}
if (j == M)
{
out[idx] = 1;
found = true;
break;
}
}
}
if(found)
{
for(int k=start;k<end;k++)
{
out_char[k] = in[k];
}
}
if(!found)
{
out[idx] = 0;
for(int k=start;k<end;k++)
{
out_char[k] = nullCharTemp;
}
//out_char[start] = ' ';
}
}
__kernel void sumReduction(__global int *A, __global int* C, int offset)
{
int global_id = get_global_id(0);
//if(get_global_size(0) < 5)
// printf("Thread id = %d", global_id);
int start = global_id * offset;
int end = start + offset;
int i;
for(i=start; i<end; i++)
{
C[global_id] += A[i];
}
}
__kernel void foldKernel(__global int *arVal, int offset)
{
int gid = get_global_id(0);
arVal[gid] = arVal[gid]+arVal[gid+offset];
}
__kernel void allOneValues(__global char* examples, __global int* yesArray, __global int* noArray, const int rowSpan,
__global char* yes, __global char* no, __global char* nullChar)
{
const int idx = get_global_id(0);
int start = (idx * rowSpan);
int end = start + rowSpan;
int N = rowSpan;
int M = 16;
bool found = false;
char nullCharTemp = nullChar[0];
if(examples[start]!=nullCharTemp)
{
for(int k=start;k<end;k++)
{
int j;
/* For current index i, check for pattern match */
for (j = 0; j < M; j++)
{
if (examples[k + j] != yes[j])
break;
}
if (j == M)
{
//out[idx] = 1;
found = true;
break;
}
}
}
if(found)
{
for(int k=start;k<end;k++)
{
//out_char[k] = in[k];
}
//printf("Found at %d", idx);
yesArray[idx] = 1;
noArray[idx] = 0;
}
if(!found)
{
//out[idx] = 0;
for(int k=start;k<end;k++)
{
//out_char[k] = nullCharTemp;
}
//out_char[start] = ' ';
yesArray[idx] = 0;
noArray[idx] = 1;
}
}
__kernel void splitDataSetNew(__global char *examplesChar, __global int* examplesInt,
const int rowSpan, __global char *pat,
const int pat_length, __global int* examplesViInt)
{
const int idx = get_global_id(0);
int start = (idx * rowSpan);
int end = start + rowSpan;
int N = rowSpan;
int M = pat_length;
bool found = false;
if(examplesInt[idx] == 1)
{
for(int k=start;k<end;k++)
{
int j;
/* For current index i, check for pattern match */
for (j = 0; j < M; j++)
{
if (examplesChar[k + j] != pat[j])
break;
}
if (j == M)
{
//out[idx] = 1;
found = true;
break;
}
}
}
if(found)
{
examplesViInt[idx] = 1;
}
else
{
examplesViInt[idx] = 0;
}
}
__kernel void splitDataSet3(__global char *examplesChar, __global int* examplesInt,
const int rowSpan, const int cellSpan, const int index, __global char *pat,
const int pat_length, __global int* examplesViInt)
{
const int idx = get_global_id(0);
int start = (idx * rowSpan + (2*index+1)*cellSpan);
int end = start + cellSpan;
//int N = rowSpan;
int M = pat_length;
bool found = false;
if(examplesInt[idx] == 1)
{
for(int k=start;k<end;k++)
{
int j;
/* For current index i, check for pattern match */
for (j = 0; j < M; j++)
{
if (examplesChar[k + j] != pat[j])
break;
}
if (j == M)
{
//out[idx] = 1;
found = true;
examplesViInt[idx] = 1;
break;
}
}
}
if(!found)
{
examplesViInt[idx] = 0;
}
}
__kernel void splitDataSet4(__global char *examplesChar, __global int* examplesInt,
const int rowSpan, const int cellSpan, const int index, __global char *pat,
const int pat_length,
__global char* yes, __global int* yesArray,
__global int* noArray, int targetIndex)
{
const int idx = get_global_id(0);
int start = (idx * rowSpan + (2*index+1)*cellSpan);
int end = start + cellSpan;
//int N = rowSpan;
int M = pat_length;
bool found = false;
if(examplesInt[idx] == 1)
{
for(int k=start;k<end;k++)
{
int j;
/* For current index i, check for pattern match */
for (j = 0; j < M; j++)
{
if (examplesChar[k + j] != pat[j])
break;
}
if (j == M)
{
//out[idx] = 1;
found = true;
//examplesViInt[idx] = 1;
}
}
}
if(found)
{
int start = (idx * rowSpan + (2*targetIndex+1)*cellSpan);
int end = start + cellSpan;
int M = 6;
bool yesFound = false;
for(int k=start;k<end;k++)
{
int j;
/* For current index i, check for pattern match */
for (j = 0; j < M; j++)
{
if (examplesChar[k + j] != yes[j])
break;
}
if (j == M)
{
//out[idx] = 1;
//found = true;
//examplesViInt[idx] = 1;
yesArray[idx] = 1;
noArray[idx] = 0;
yesFound = true;
break;
}
}
if(!yesFound){
noArray[idx] = 1;
yesArray[idx] = 0;
}
}
else{
yesArray[idx] = 0;
noArray[idx] = 0;
}
}
__kernel void getCount(__global char *examplesChar, __global int* examplesInt,
const int rowSpan, const int cellSpan, const int index, __global char *pat,
const int pat_length, __global int* countArray)
{
const int idx = get_global_id(0);
int start = (idx * rowSpan + (2*index+1)*cellSpan);
int end = start + cellSpan;
//int N = rowSpan;
int M = pat_length;
bool found = false;
if(examplesInt[idx] == 1)
{
for(int k=start;k<end;k++)
{
int j;
/* For current index i, check for pattern match */
for (j = 0; j < M; j++)
{
if (examplesChar[k + j] != pat[j])
break;
}
if (j == M)
{
//out[idx] = 1;
found = true;
countArray[idx] = 1;
break;
}
}
}
if(!found)
{
countArray[idx] = 0;
}
}