Snakecy's NOTE


  • Home

  • Archives

  • About

  • Search

Ipinyou DataSet Description

Posted on 2016-03-10   |   In cloud-tech   |     |   Views

iPinyou Reference


Ipinyou database
Features = {IP,Region,City,Ad exchange,ad slot id,ad slot width, ad slot height,ad visiblility,ad slot format,advertiser id,user tags}


  • RankSorce = CTR * BidPrice
    • Advertising Calculating
  • Aim
    • Low-latency and scalale predictions as a service
    • Integrated approach leads to fresher, better predictions
    • Easy translation to production predictions
    • Eases Operational pain
Read more »

Machine Learning with Scala

Posted on 2016-03-10   |   In cloud-tech   |     |   Views

Good Example: REST API & Velox PPT, Papre, Github


Construct project, with SBT & dependencies

The reference example project can be found on my github

  • think-bayes [github], [Repository]
    • probability density function of the standard normal distribution & cumulative density function of the standard normal distribution
      1
      - libraryDependencies += "net.ruippeixotog" % "think-bayes_2.11" % "0.1"
Read more »

Java call Matlab Method

Posted on 2016-03-06   |   In open-source   |     |   Views

环境准备

+ Eclipse & Matlab
  1. JAVA_HOME
    • i. JAVA_HOME (JDK的安装位置 如C:\Program Files\Java\jdk1.5.0)
      • 设置后,重启matlab才能有效.
      • 用getenv JAVA_HOME,在Matlab的命令窗口中试验,看看得到的返回值正确方可说明其对Matlab生效了。
    • ii. Classpath
      • 添加 matlabInstallRoot\toolbox\javabuilder\jar\javabuilder.jar
    • iii. Path
      • 添加%JAVA_HOME%/bin/javac
  2. build matlab m-file into a jar
    • a) 在matlab的command窗口,输入 deploytool。会在右侧弹出一个新窗口(Deployment Tool)。
    • b) 在Deployment Tool中,点击new按钮,选择 Matlab Builder for Java 与 Java Package。新建一个工程名字,如flying.prj 。对该工程,要进入其设置对话框,设置其compiler为“matlabInstallRoot\toolbox\javabuilder\jar\javabuilder.jar ”。
    • c) In the Deployment Tool pane, ensure that the Generate Verbose Output option is selected
    • d) 将欲被java调用的.m 文件,(如mydraw.m,其中包括两个参数(x,y)),从Matlab整个界面的左侧工作目录面板,拖拽到Deployment Tool中的新建的类下面的class文件夹下。
    • e) 点击build 按钮,则会在matlab的当前目录下,生成以一个与工程同名的(如flying)文件夹。
      Read more »

Sorting Algorithm (02)

Posted on 2016-03-05   |   In algorithm   |     |   Views

Sorting Algorithm

排序算法比较

  • Bubble Sort (冒泡排序)
  • Insertion Sort (插入排序)
  • Selection Sort (选择排序)

Java实现排序算法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.io.*;
public class Paixu {
// 冒泡排序法
public void Maopao(int a[]) {
for (int i = 1; i < a.length; i++) {
for (int j = 0; j < a.length - i; j++) {
if (a[j] > a[j + 1]) {
int temp = a[j + 1];
a[j + 1] = a[j];
a[j] = temp;
}
}
}
System.out.println("\n" + "采用冒泡排序法:");
}
// 插入排序法:
public void Charu(int a[]) {
for (int i = 1; i < a.length; i++) {
for (int j = 0; j < i; j++) {
if (a[j] > a[i]) {
int temp = a[i];
for (int k = i; k > j; k--) {
a[k] = a[k--];
}
a[j] = temp;
}
}
}
System.out.println("\n" + "采用插入排序法:");
}
// 选择排序法:
public void Xuanze(int a[]) {
for (int i = 0; i < a.length; i++) {
int position = i;
for (int j = i + 1; j < a.length; j++) {
if (a[position] > a[j]) {
int temp = a[position];
a[position] = a[j];
a[j] = temp;
}
}
}
System.out.println("\n" + "采用选择排序法:");
}
public void Print(int a[]) {
System.out.println("从小到大排序结果为:");
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + ",");
}
}
public static void main(String[] args) {
int a[] = new int[5];
Paixu px = new Paixu();
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("请输入五个整数:");
for (int i = 0; i < a.length; i++) {
try {
String s = buf.readLine();
int j = Integer.parseInt(s);
a[i] = j;
} catch (Exception e) {
System.out.println("出错了!必须输入整数,请重新输入!");
i--;
}
}
System.out.println("您输入的整数依次为:");
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + ",");
}
System.out.println("\n" + "-------------");
px.Maopao(a); // 调用冒泡算法
px.Print(a);
System.out.println("\n" + "-------------");
px.Charu(a); // 调用插入算法
px.Print(a);
System.out.println("\n" + "-------------");
px.Xuanze(a); // 调用选择算法
px.Print(a);
}
}

Binary Search Algorithm (01)

Posted on 2016-03-05   |   In algorithm   |     |   Views

Binary Search(二分查找)

Java实现二分查找

在一个有序的集合中查找元素,可以使用二分查找算法,也叫二分搜索。二分查找算法先比较位于集合中间位置的元素与键的大小,有三种情况(假设集合是从小到大排列的):

  1. 键小于中间位置的元素,则匹配元素必在左边(如果有的话),于是对左边的区域应用二分搜索。
  2. 键等于中间位置的元素,所以元素找到。
  3. 键大于中间位置的元素,则匹配元素必在右边(如果有的话),于是对右边的区域应用二分搜索。另外,当集合为空,则代表找不到。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.util.*;
public class BinarySearch {

public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList<Integer>();
addIntegerInSequence(a,1,10);
print(a);
int pos = binarySearch(a,10);
if ( pos != -1 )
{
System.out.print("Element found: " + pos);
}
else
{
System.out.print("Element not found");
}
}

/**
* 二分查找法
* @param a
* @param value 待查找元素
* @return
*/
public static int binarySearch(ArrayList<Integer> a, int value)
{
int size = a.size();
int low = 0 , high = size - 1;
int mid;
while (low <= high)
{
mid = (low + high) / 2;
if ( a.get(mid) < value )
{
low = low + 1;
}
else if ( a.get(mid) > value )
{
high = high - 1;
}
else
{
return mid;
}
}
return -1;
}

/**
* 填充顺序元素到数组
* @param a
* @param begin 开始元素
* @param size 大小
*/
public static void addIntegerInSequence(ArrayList<Integer> a, int begin, int size)
{
for (int i = begin; i < begin + size; i++)
{
a.add(i);
}
}

/**
* 打印数组
* @param a
*/
public static void print(ArrayList<Integer> a)
{
Iterator<Integer> i = a.iterator();
while (i.hasNext())
{
System.out.print(i.next() + " ");
}
System.out.println("");
}

}

//JAVA 库中的二分查找使用非递归方式实现,返回结果与前面写的有所不同:找不到时返回的是负数,但不一定是-1
private static int binarySearch0(int[] a, int fromIndex, int toIndex,
int key) {
int low = fromIndex;
int high = toIndex - 1;

while (low <= high) {
int mid = (low + high) >>> 1;
int midVal = a[mid];

if (midVal < key)
low = mid + 1;
else if (midVal > key)
high = mid - 1;
else
return mid; // key found
}
return -(low + 1); // key not found.
}
123…5
SZhou

SZhou

The unexamined life is not worth living. --Socrates

24 posts
5 categories
22 tags
RSS
GitHub LinkedIn Weibo
Creative Commons

Links

DataTopics Chinabyte
© 2016 SZhou
Powered by Hexo
Theme - NexT.Mist
  |   hits from vistors