Latest Entries »

A question

There are 2 sets, A and B

A relation R map A’s elements to B’s elements.

R(a)=b

for each a, there may be more than 1 b existing in B, that is, R is a 1-n relation.

Write a program to list all sub sets of A which meet below:

  • All B elements are covered
  • the size of these sub sets is the least

How to build jocl

opencl can be used  to speed up data processing,and jocl is a java binding to opencl。To use it,the first step is to build it。

Take a look at http://www.jocl.org/documentation/documentation.html firstly。

Then install one of opencl implementation, Say nvidia. https://developer.nvidia.com/opencl

Go to https://github.com/gpu/JOCL for instructions to build jocl.

git clone https://github.com/gpu/JOCL.git
git clone https://github.com/gpu/JOCLCommon.git

Download cmake, and take below steps to build JOCL_2_0_1-windows-x86_64.dll
locaed at E:\JOCLRoot\JOCL\nativeLibraries

Start cmake-gui,
Set the directory containing the sources of the JOCL project, e.g. C:\JOCLRoot\JOCL
Set the directory for the build files: e.g. C:\JOCLRoot\JOCL.build
Press "Configure" (and select the appropriate compiler)
Press "Generate"

Download maven, and build jocl-2.0.3-SNAPSHOT.jar

mvn clean install

set PATH=%PATH%;C:\Program Files\Java\jdk-13.0.1\bin
set PATH=%PATH%;C:\Program Files (x86)\apache-maven-3.6.3\bin
set JAVA_HOME=C:\Program Files\Java\jdk-13.0.

If there is an error:

[ERROR] Failure executing javac, but could not parse the error:
错误: 不再支持源选项 6。请使用 7 或更高版本。
错误: 不再支持目标选项 6。请使用 7 或更高版本。

modify jocl pom.xml from 1.6 to 13 assuming java13 is used

<plugin>
    < groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>13</source>
         <target>13</target>
    </configuration>
< /plugin>

That is all. 3 parts are needed to call opencl from java.

  • The nvidia driver,
  • jocl*.jar
  • JOCL*.dll

Build and run joclsamples

Go to https://github.com/gpu/JOCLSamples, and clone it

mvn clean install

需要用-cp指明jocl.jar和jocl-samples.jar的路径

java -cp "E:\\JOCLRoot\\JOCLSamples\\jocl-2.0.2.jar;E:\\JOCLRoot\\JOCLSamples\\target\\jocl-samples-0.0.1-SNAPSHOT.jar" org.jocl.samples.JOCLSample

    Java tips

    1. FileUtils.wirteStringToFile(…)是否支持多线程?
    2. 比如多个线程写同一文件

      https://stackoverflow.com/questions/13463662/java-library-like-org-apache-commons-io-fileutils-but-contains-instance-methods

      这个link的答复似乎是不支持

      However if you try e.g. to write to the same file from within multiple threads you may have some problems.

      但在windows上测试的结果是没有问题的,似乎FileOuputStream的内部实现,自动同步了多个线程race condition

    3. class static variable initialization
      there are 2 ways to init a class static variable:
    4. public static int mB=10;   //way1
      static {
          mB=5;                          //way2
      }
      which one is done firstly? way1, so way2 will override way1.

            

    5. Usage of HashMap, Hashtable, ConcurrentHashMap
      单线程 情况下用HashMap;multithreads强调synchronization用Hashtable,因为Hashtable是对整个map锁定; multithreads强调效率,用ConcurrentHashMap,因为它仅对部分数据结构锁定;
    6.      

    7. Lambda expression
      Lambda表达式也不是什么新东西,一句话概括就是实现只有1个abstract method的interface         
              lambda-expression
    8. import Java.util.*;
      public class GFG {
       
          public static void main(String[] args) throws Exception
          {
       
              List<String> arr1 = new ArrayList<String>();
               int count = 0;
              arr1.add("Geeks");
              arr1.add("For");
               arr1.add("Geeks");
              arr1.stream().forEach(s -> {       
               
                  // print all elements
                   System.out.print(s);
              });
          }
      }
      forEach中就是1个Lambda表达式,实现了Consumer接口中的accept(T) method,Consumer中唯一的abstract method

    9. NaN of double
      assuming d is a double, boolean expression d==Double.NaN always return false even if d==Double.NaN
      Instead Double.isNaN(d) should be used
    10. This is a vb tip to handle char “
      Dim dq As String
      dq = """123"     ‘”” is used to parse “
      Anad the result is to get a string “123
    11. Rmi
      Surely there is an rmi thread pool to execute object methods. So for each call to obj.method(), should jvm fork a new thread to execute it? No, for each call of registry.lookup(url) in client’s thread A, a stub is returned. Subsequent calls to stub.method() in this client’s thread A will all be executed in same server thread.

    http://baijiahao.baidu.com/s?id=1632151660141484205

    要点就是:

    1. n个量子位能同时编码(0,2^n-1)共2^n个数
    2. 但某个时刻只能观测(读取和写入)这2^n个数字中的某一个
      即这些数以某种概率出现(被读取和写入),总和为1

    不过它没回答,这些数对应的概率是怎么被确定下来的?

    那么对于一台32位拥有4G内存的传统计算机来说,它符合前提1;

    另外只要满足一定条件,符合前提2也是可以的。

    所以可以认为一台32位4G内存传统计算机可以模拟一组32个量子位。

    n台32位4G内存传统计算机可以模拟n组32个量子位。

      Godel theorem confuses me for a long time。It is a good chance now for me to make it clear。

      But before that there are some basic points。

      1. System
        System is made by Definition,Axioms,theorem;
        Definition describes the object which we care
        Axiom and theorem are what we can do with the definition
      2. Statement
        In the system,we can say anything starting from the definition.
        And what we say is a statement.
        A statement can either true or false.         
        Axiom and theorem are true statements,but there are also other statements which may be deduced to be true or false
        There are 4 kinds of combination for a statement:
        T = True
        F = False
        B = Both         
        N = Neither

        a B statement can be proved both true and false
        a N statement can not be proved true or false, so it is unprovable

        True False Both Neither
        provable provable provable

        unprovable

      3. Consistence
        Consistence is about a system.
        If a system contains no axioms of Both, then this system is consistent               

      4. Complete&Incomplete       
      5. Any system with a N statement is called incomplete.
        A system is called complete if there is no N statement.
          

        Complete No N
        Incomplete Some N


      Here is the Godel incompleteness theorem:

          If you have a consistent logical system (i.e., a set of axioms with no contradictions) in which you can do a certain amount of arithmetic, then there are statements in that system which are unprovable using just that system’s axioms.

      翻译过来就是:

          如果某个可以做算术操作的逻辑系统是一致的,那么这个系统一定存在着(仅从公理推导不出来的)【不可证明的】声明

      How does Godel prove his incompleteness theorem?
      Here is the rough idea:

      1. Construct a special statement for a Consistent system
        most contents of the Godel Incomplete theorem is about the trick to make such a special statement
      2. If this statement is T, Godel can prove it F
      3. If this statement is F, Godel can prove it T
      4. So this special statement must be a N statement
      5. So a Consistent system must be an Incomplete system

      ref:

        条件概率和贝叶斯定理

        条件概率是指事件A在事件B确定发生下的概率,符号定义是P(A|B)

        联合概率是指事件A和B共同发生的概率,符合定义是P(AB)

        边缘概率是指某个事件A发生的概率,符号定义是P(B)

        AB共同发生,可以分解为

        • 先发生B,那么P(B)
        • 在B确定发生的前提下,再发生A,那么P(A|B)

        这是一个乘法的关系,所以它们的联系是:

        • P(B)*P(A|B)=P(AB)

        那么当P(B)!=0时,条件概率的计算公式是:

        • P(A|B)=P(AB)/P(B)
        • 即条件概率=联合概率/边缘概率

        贝叶斯定理是怎么回事?

        由条件概率定义,

        • P(AB)=P(B)*P(A|B)
        • P(BA)=P(A)*P(B|A)

        另外,P(AB)=P(BA),所以

        • P(B)*P(A|B) = P(A)*P(B|A)

        所以,

        • P(A|B) = P(A)*P(B|A)/P(B)                         公式1

        公式1就是贝叶斯定理,

        可以用文氏图表示

        image

        • 整个矩形面积是1
        • 左圆是事件A发生的概率P(A),右圆是事件B发生的概率P(B)
        • 两圆相交即为AB同时发生的概率P(AB)
        • 相交部分面积/左圆面积,即P(B|A)
        • 相交部分面积/右圆面积,即P(A|B)

        附注(some statistics variable)

        U= E(X)

        Var(X) = E((X-U)^2)

        Q(X) = sqrt(Var(X))

        Cov(X,Y) = E((X-Ux)(Y-Uy))

        P(X,Y) = Cov(X,Y)/(Q(X)*Q(Y))

        AB相互独立的直观解释

        概率论经常遇到的一个概念是事件A和B相互独立,字面的意思是相互不影响

        严格的数学定义: 
          如果P(AB)= P(A)*P(B),那么AB相互独立
        可以这么理解

        • imageimageimage中的概率都是P(A)
        • imageimageimage中的概率都是P(B)

        如果用树来表示,是这样的

        • 前提
          P(A)=p      P(B)=q                   

                 

        • 相互独立

        image=A不发生,image=A发生,image=B不发生,image=B发生

        image

        B在A发生的前提下概率是q,即image,红色路径

        B在A不发生的前提下概率依然是q,即image,黄色路径

        • 相互不独立

        image

        B在A发生的前提下概率是s,即image,红色路径

        B在A不发生的前提下概率是r,即image,黄色路径

        其中image  image只要有1个成立即可
               

        Maybe we can be put into a system,and be represented as be a number。

        This number indicates what we are and describes what we shall do in next step。

        So is there a rational number for a human?

        In mathematics, irrational number means non-cycle limitless number.

        Since a human is always of limit(his life is limited), he is always a rational number if it can be encoded a number.

        (These are 2 different concepts, a human’s limited life and his encoded number’s length are different)

        note20180310:

        1. Maybe not a number, but a group of independent numbers
        2. Maybe a group of both independent and dependent numbers
        3. Could these independent and dependent numbers be encoded as a number?

        方向、偏差

        均可用数字来描述

        slope

        R^2,这个参数的提出赞点在于是相对的,绝对的不好比较

            明明是个绝对参数,却能找到一个相对参数来衡量

            如何能提出一个指标,是必修的能力之一

        预定义偏差范围,就能区分各种方向。

         

        很显然,需要对它的技术做修改。

        所谓深度学习技术,其实是一种自下而上的技术,通过输入大量的数据,结合神经网络,总结出规律(总结出1个函数?函数拟合?)。

        对于1个天才来说,它本身不需要学习。

        深度学习技术,不过是把天才的行为函数化(自动化?系统化?)罢了,或者说解密天才的行为。

        有意思的是,alphago团队本身并无1个围棋的职业选手,只有黄士杰是个业余n段兼围棋开发者;而且当5翻棋第4局出现bug之后,alphago的创造者回答提问也很有意思,“他们也不晓得alphago是如何学习的?”

        alphago创造者虽然创造了alphago,但alphago的执行能力强于创造者,而且alphago的具体执行过程甚至创造者都未必能100%掌控。