<commit_before>/**
 * scan.c
 * Authors: <NAME> <<EMAIL>>
 * Date: {08/01/2017}
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>

void getWindowCandI(double * x, double * y, int * nCass, double * intensity, int locCount, double wSize, int wCount, int * casInW, double * intenInW) {
	double distance;
	int minWindow;

	for(int i = 0; i < locCount * wCount; i++) {
		casInW[i] = 0;
		intenInW[i] = 0.0;
	}

#pragma omp parallel for private(distance, minWindow)
	for(int i = 0; i < locCount; i++) {
		for(int j = 0; j < locCount; j++) {
			distance = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			minWindow = (int)(ceil(distance / wSize));
			if(minWindow > 0)
				minWindow --;
			for(int k = minWindow; k < wCount; k++) {
				casInW[i * wCount + k] += nCass[j];
				intenInW[i * wCount + k] += intensity[j];
			}
		}
	}

	return;
}

void getWindowCOnly(double * x, double * y, int * nCass, int locCount, double wSize, int wCount, int * casInW) {
	double distance;
	int minWindow;
	
	for(int i = 0; i < locCount * wCount; i++) {
		casInW[i] = 0;
	}

#pragma omp parallel for private(distance, minWindow)
	for(int i = 0; i < locCount; i++) {
		for(int j = 0; j < locCount; j++) {
			distance = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			minWindow = (int)(ceil(distance / wSize));
			if(minWindow > 0)
				minWindow --;
			for(int k = minWindow; k < wCount; k++) {
				casInW[i * wCount + k] += nCass[j];
			}
		}
	}

	return;
}

void loglikelihood(double * ll, int * casInW, double * intenInW, int totalWindow, int casCount, int highLow) {
	double cas, inten;
	double llTemp;
	bool highCluster = true;
	bool lowCluster = true;
	if(highLow == 1)
		lowCluster = false;
	else if(highLow == -1)
		highCluster = false;

#pragma omp parallel for private(cas, inten, llTemp)
	for(int i = 0; i < totalWindow; i++) {
		cas = casInW[i];
		inten = intenInW[i];

		if(cas == -1) {
			ll[i] = -9999;
		}
		else if(cas > inten) { //High cluster of cases
			if(highCluster) {
				llTemp = cas * log(cas/inten);
				if(cas < casCount)
					llTemp += (casCount - cas) * log((casCount - cas)/(casCount - inten));
				ll[i] = llTemp;<commit_msg>change poisson scan.c<commit_after>/**
 * scan.c
 * Authors: <NAME> <<EMAIL>>
 * Date: {08/01/2017}
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>

void getWindowCandI(double * x, double * y, int * nCass, double * intensity, int locCount, double wSize, int wCount, int * casInW, double * intenInW) {
	double distance;
	int minWindow;

	for(int i = 0; i < locCount * wCount; i++) {
		casInW[i] = 0;
		intenInW[i] = 0.0;
	}

#pragma omp parallel for private(distance, minWindow)
	for(int i = 0; i < locCount; i++) {
		for(int j = 0; j < locCount; j++) {
			distance = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			minWindow = (int)(ceil(distance / wSize));
			if(minWindow > 0)
				minWindow --;
			for(int k = minWindow; k < wCount; k++) {
				casInW[i * wCount + k] += nCass[j];
				intenInW[i * wCount + k] += intensity[j];
			}
		}
	}

	return;
}

void getWindowCOnly(double * x, double * y, int * nCass, int locCount, double wSize, int wCount, int * casInW) {
	double distance;
	int minWindow;
	
	for(int i = 0; i < locCount * wCount; i++) {
		casInW[i] = 0;
	}

#pragma omp parallel for private(distance, minWindow)
	for(int i = 0; i < locCount; i++) {
		for(int j = 0; j < locCount; j++) {
			distance = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			minWindow = (int)(ceil(distance / wSize));
			if(minWindow > 0)
				minWindow --;
			for(int k = minWindow; k < wCount; k++) {
				casInW[i * wCount + k] += nCass[j];
			}
		}
	}

	return;
}

void loglikelihood(double * ll, int * casInW, double * intenInW, int totalWindow, int casCount, int highLow) {
	double cas, inten;
	double llTemp;
	bool highCluster = true;
	bool lowCluster = true;
	if(highLow == 1)
		lowCluster = false;
	else if(highLow == -1)
		highCluster = false;

#pragma omp parallel for private(cas, inten, llTemp)
	for(int i = 0; i < totalWindow; i++) {
		cas = casInW[i];
		inten = intenInW[i];

		if(cas == -1 || inten < 0.000001) {
			ll[i] = -9999;
		}
		else if(cas > inten) { //High cluster of cases
			if(highCluster) {
				llTemp = cas * log(cas/inten);
				if(cas < casCount)
					llTemp += (casCount - cas) * log((casCount - cas)/(casCount - inten));
				ll[i] = llTemp;
{'fraction_non_alphanumeric': 0.18609360936093608, 'fraction_numerical': 0.014176417641764177, 'mean_word_length': 3.119555143651529, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6674321', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1823, 'n_words': 491}