Skip to content

Instantly share code, notes, and snippets.

@taroyabuki
taroyabuki / codeiq_q153.py
Last active December 11, 2015 19:28
CodeIQ「NumpyとScipyで統計基本復習」https://codeiq.jp/ace/tsuji_shingo/q153
# -*- coding: utf-8 -*-
import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt
ss.binom.rvs(10, 0.3)
np.random.binomial(10, 0.3)
@taroyabuki
taroyabuki / bug_in_table.m
Last active December 11, 2015 21:18
http://blog.unfindable.net/archives/5410Bug in Mathematica 8.0.4, 9.0.0, 9.0.1 for Microsoft Windows (64-bit) (December 12, 2012).To avoid this issue, you need run the following command:SetSystemOptions["CompileOptions" -> {"TableCompileLength Infinity}]
f[] := With[{p = RandomVariate[NormalDistribution[]]}, If[0 <= p, p, f[]]]
data = Table[f[], {249}]; (* no problem *)
data2 = Table[f[], {250}]; (* crash! *)
g[] := With[{p = RandomVariate[BinomialDistribution[10, 1/10]]}, If[0 <= p, p, g[]]]
data = Table[g[], {249}]; (* no problem *)
#include <stdio.h>
#define N 9
#define B 3 //square root of N
int canBePlaced(int board[], int pos, int x)
{
int row=pos/N;
int col=pos%N;
int i, j, topLeft;
@taroyabuki
taroyabuki / clustering_test_data.csv
Created February 10, 2013 10:45
MathematicaのAgglomerateのバグ http://blog.unfindable.net/archives/5504 MathematicaのAgglomerateのバグ http://blog.unfindable.net/archives/5556
0 0 0 0 0 0 7 0 0 0 0 0
2 2 0 0 0 0 0 0 0 0 2 4
0 0 10 0 0 0 0 0 0 0 0 0
0 0 0 0 5 0 0 0 0 0 0 0
0 0 0 0 0 0 2 0 0 0 4 0
0 0 0 0 0 0 0 0 3 0 0 0
0 0 6 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 2 0
0 0 0 0 0 3 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0 0 0
@taroyabuki
taroyabuki / bug_in_findclusters.m
Last active December 12, 2015 09:09
Bug in FindClusters of Mathematica 8.0.4, 9.0.0, and 9.0.1.
data = Import["https://gist.github.com/taroyabuki/4749183/raw/ffc84dbc4a3499ddef4a8c4f689b56c2948225bd/clustering_test_data.csv"];
(* This returns no result *)
FindClusters[data, DistanceFunction -> CosineDistance,
Method -> {"Agglomerate", "Linkage" -> "Complete"}]
(* Shuffled data can be clustered. *)
FindClusters[RandomSample@data, DistanceFunction -> CosineDistance,
Method -> {"Agglomerate", "Linkage" -> "Complete"}]
samples <- data.frame(
x = c(3, 7, 10),
y = c(7, 1, 8),
row.names = c("A", "B", "C"))
plot(samples, type = "n")
text(samples[,1], samples[,2], row.names(samples))
d <- dist(samples)
install.packages("RCurl")
install.packages("lsa")
library(RCurl)
url <- getURL("https://gist.github.com/taroyabuki/4749183/raw/ffc84dbc4a3499ddef4a8c4f689b56c2948225bd/clustering_test_data.csv", ssl.verifypeer = F)
data <- read.csv(textConnection(url), header = F)
library(lsa)
d <- dist(1 - cosine(t(as.matrix(data))))
hr <- hclust(d, method = "complete")
@taroyabuki
taroyabuki / bug_in_agglomerate.m
Last active December 13, 2015 23:59
Bug in Agglomerate of Mathematica 8.0.4 and 9.0.1.
Needs["HierarchicalClustering`"]
data = Import["https://gist.github.com/taroyabuki/4749183/raw/ffc84dbc4a3499ddef4a8c4f689b56c2948225bd/clustering_test_data.csv"];
clusters = Agglomerate[data, DistanceFunction -> CosineDistance, Linkage -> "Complete"];
On[Assert];
Assert[Length@ClusterFlatten@clusters == Length@data]
{Length@ClusterFlatten@clusters, Length@data}
@taroyabuki
taroyabuki / clustering_test_data2.csv
Created February 20, 2013 14:54
MathematicaのClusteringComponentsの困ったところ http://blog.unfindable.net/archives/7727
0.07832604499879574 0. 0. 0. 0.2170723815877265 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.6432675209026769 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0.5601120336112039 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.20965696734438366 0.24253562503633297
0. 0. 0.5312532024908597 0.23791547571544325 0. 0. 0. 0. 0. 0. 0. 0.
0. 0.15961737689352443 0. 0.15861031714362883 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.5360562674188974 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0.42008402520840293 0. 0. 0.
0. 0. 0. 0.4758309514308865 0. 0. 0. 0. 0. 0. 0. 0.
0.15665208999759148 0.15961737689352443 0. 0. 0. 0. 0. 0. 0. 0. 0.20965696734438366 0.48507125007266594
<?php
session_start();
$_SESSION['consumer_key'] = 'Consumer Key';
$_SESSION['consumer_secret'] = 'Consumer Secret';
$callbackUrl = 'http://localhost/twitter/twitter-oauth-end.php';
$oauth = new OAuth($_SESSION['consumer_key'], $_SESSION['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
if (substr(PHP_OS, 0, 3) == 'WIN') {//XAMPP(いいかげん)
$caPath = 'C:/xampp/perl/vendor/lib/Mozilla/CA/';