Skip to content

Instantly share code, notes, and snippets.

@sasekazu
sasekazu / gist:dce32323ad04a0f60c9c
Last active August 29, 2015 14:13
最小二乗法による直線の当てはめ least square
// numeric.jsを使用
// データ点を配列で渡す 例: points = [[x0,y0],[x1,y1],[x2,y2],[x3,y3]];
// y=c[0]*x+c[1] で近似し係数cを配列で返す
function leastSquare(points) {
var A=numeric.rep([2, 2], 0);
var b=numeric.rep([2], 0);
for(var i=0; i<points.length; ++i) {
A[0][0]+=points[i][0]*points[i][0];
A[0][1]+=points[i][0];
A[1][0]+=points[i][0];
@sasekazu
sasekazu / gist:a406c51adca34a37f2cc
Created January 10, 2015 09:38
jacobi法による対角化 jacobi diagonalization
// jacobi法による実対称行列の対角化
// numeric.jsが必要
// 他の関数との依存性排除ver
// size: 行列サイズ
// intputA: 対角化される入力行列 ※対称行列でなければならない
// 返り値 {DiagonalMatrix:A, OrthodonalMatrix:P};
// A(入力時) = P A(対角化後) P.transpose が成り立つ
function jacobiDiagonalization(size, inputA, maxIteration, threshold) {
var A=numeric.clone(inputA);
@sasekazu
sasekazu / gist:b1471424607cc37174a9
Created January 8, 2015 08:24
点列データをSVGに変換して書き出す
#include <iostream>
#include <fstream>
#include <list>
#include <math.h>
#define N 2000
#define PI 3.141592
using namespace std;
@sasekazu
sasekazu / gist:bac785784e17e625a724
Created January 5, 2015 13:38
HTML5 canvas 画像処理 輪郭追跡 Freeman chain code
// 輪郭追跡を行い,輪郭部のみに色を出力する
function contourDetection(contextIn, contextOut, width, height) {
var imgData=contextIn.getImageData(0, 0, width, height);
// 読み取り用ピクセルデータ(書き換えない)
var pixelData = new Array(width);
for(var i=0; i<width; ++i) {
pixelData[i] = new Array(height);
for(var j=0; j<height; ++j) {
pixelData[i][j] = imgData.data[4*(width*j+i)];
}
@sasekazu
sasekazu / gist:ca74de14c92d48acfe91
Created January 5, 2015 13:36
HTML5 canvas 画像処理 二値化
// 二値化
// canvasコンテキスト contextIn を閾値 threshold の元で二値化して contextOut に書き出す
// 入力画像はグレースケール画像であることを想定している(RGB値がすべて同じ)
// アルファ値が 0 のピクセルは閾値に関わらず白にする
function binarization(contextIn, contextOut, width, height, threshold) {
var imgData = contextIn.getImageData(0, 0, width, height);
var gray;
for(var i=0; i<imgData.width*imgData.height; ++i) {
if(imgData.data[4*i+3]==0) {
imgData.data[4*i] = 255;
@sasekazu
sasekazu / gist:2faafd364daa849d937f
Created January 5, 2015 13:35
HTML5 canvas 画像処理 グレースケール化
// グレースケール化
// canvasコンテキスト contextIn をグレースケール化して contextOut に書き出す
// ただしアルファ値が 0 のピクセルはそのままにする
function grayScale(contextIn, contextOut, width, height) {
var imgData = contextIn.getImageData(0, 0, width, height);
var gray;
for(var i=0; i<imgData.width*imgData.height; ++i) {
if(imgData.data[4*i+3]!=0) {
gray = 0.299*imgData.data[4*i]+0.587*imgData.data[4*i+1]+0.114*imgData.data[4*i+2];
gray = Math.floor(gray);
@sasekazu
sasekazu / gist:37a4a522b4ef9e7b0fcd
Last active August 29, 2015 14:11
ロジスティック写像の分岐図 写像の可視化付き
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>logistic</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
@sasekazu
sasekazu / gist:1c1acd437b7a4466d50c
Last active August 29, 2015 14:11
ロジスティック写像の分岐図
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>logistic</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var canvas = document.getElementById('myCanvas');
@sasekazu
sasekazu / gist:34b8dcdbdfd4175246b5
Created November 6, 2014 03:09
Thrust sort time measure
/*
* main.cu
*
* Created on: 2014/11/05
* Author: sase
*/
/*
* tbbTest.cpp
@sasekazu
sasekazu / gist:827ca7d5dadda0c34ac6
Created November 6, 2014 03:08
Intel TBB sort time measure
/*
* tbbTest.cpp
*
* Created on: 2014/11/05
* Author: sase
*/
#include <iostream>
#include <math.h>
#include <sys/time.h>