2017-01-01から1年間の記事一覧

Start learning Rust

I don’t know the reason, but I want to do something different from what I’m usually doing. And I want to have a familiar programming language which does not have garbage collection (GC). There are two candidates for me, swift and Rust. I t…

Cast a List type object without iteration

There are three choices as follows: List<String> list = Arrays.asList("1","2"); List<Object> objectList = (List) list; List<Object> objectList2 = (List<Object>)(List) list; List<Object> objectList3 = new ArrayList<Object>(list); But the choice 1 and 2 seem to be dangerous because the ex</object></object></object></object></object></string>…

Job Scheduler

Since scheduled tasks of my project has some dependencies, I’m thinking whether I should use a job scheduler. There are lots of job schedulers and lots of comparison of job schedulers. My requirements are 1. Manages DAGs which define job d…

HttpClient in Java

Both Apache HttpClient and OkHttpClient are thread-safe. Apache HttpClient HttpClient - HttpClient Performance Optimization Guide Chapter 2. Connection management OkHttpClient Concurrency · square/okhttp Wiki · GitHub OkHttp3 does not use …

Markov Chain Monte Carlo

One of the goal of the current my study about statistics is understanding Markov Chain Monte Carlo(MCMC). I would like to write about one of the popular algorithms of MCMC, Metropolis–Hastings algorithm. It’s a kind of rejection sampling a…

Multiple-Column Indexes on MySQL

MySQL can use multiple-column indexes for queries that use all the columns, the first two columns, the first three columns and so on. MySQL :: MySQL 5.7 Reference Manual :: 9.3.5 Multiple-Column Indexes The following index is equivalent to…

Reversible Markov Chain

In the previous post, I introduced some of important Markov chain properties. I would like to write about a Markov chain property that is used in Markov Chain Monte Carlo(mcmc), which is reversibility. Reversibility Let is a variable of a …

Markov Chain Properties

In the previous post, I gave the definition of Markov chain and as you can see in the page that I introduced in the previous post, a Markov chain can be represented by a directed graph. Each node represents a state and each edge of the gra…

Markov Chain

Markov Chain is a sequence of random variables () which has a property that the probability of moving to the next step depends only on the current state not on the previous states. The probability of moving to the next step which is define…

Bayes' theorem

When I learned Bayesian Inference, it recalls me the proof of Bayes' theorem. It’s one of the simplest proof which derives an important theorem. Let be an event. The following formula are the definition of conditional probability. Do a sim…

Bayesian Inference

Bayesian Inference is a method for estimating a true probability distribution from samples of the distribution. When I read the article in the wikipedia, I didn’t get the point. But I found a better article that gives me more intuitive und…

Implementing Box-Muller Transform

After writing [the previous post, I think I understand Box-Muller transform. I’m implementing it in this post. Original form of Box-Muller transform is as follows: : random variables from uniform distribution (0,1) However it includes squa…

Box Muller Transformation

When I read the post, I got an intuitive understanding of Box Muller Transformation because it has a lot of images. However I didn’t think I fully understand Box-Muller transformation and I didn’t understand the reason why we need to draw …

Draw a sample from a normal distribution with mean 0 and variance 1

In the previous post, it’s easy to transform it to a sample from a normal distribution with mean and variance by calculating if we can draw a sample x from a normal distribution with mean 0 and variance 1. Then I started googling how to dr…

Sample(Generate random variables) from normal distribution

In the following previous posts, I mentioned about rejection sampling. nakaly.hatenablog.com nakaly.hatenablog.com But I was a little confused when I learn rejection sampling. Because we need a known distribution which we already know how …

Plotting in python

Before going to MCMC, I would like to implement a test code by using rejection sampling. Since I am a little bit familiar with python, I’m choosing python(python3). And I would like to plot the result that I draw from a distribution to see…

Proof of Rejection Sampling

In previous post, I introduced the simple idea of rejection sampling algorithm. But the step 2 (Accept the sample with a probability ()) should be elaborated when you actually use it. Draw a sample from G (which is a known distribution tha…

Rejection Sampling

In previous post, I mentioned about the naive sampling method. I would like to mention about rejection sampling which is more efficient than the naive method. You have the target distribution(F) which you would like to draw samples from. A…

Regular Expression for domain validation

A very simple example: ^[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+){1,}$ From org.apache.common.validator: DOMAIN_LABEL_REGEX \p{Alnum}(?>[\p{Alnum}-]*\p{Alnum})* TOP_LABEL_REGEX \p{Alpha}{2,} DOMAIN_NAME_REGEX ^(?:" + DOMAIN_LABEL_REGEX + "\.)+" + "("…

Sampling

When I learned about machine learning (especially deep learning), I sometimes see the word “sampling” such as gibbs sampling, MCMC. However I don’t think I fully understand sampling. I start learning it. When I think sampling, the first th…

Live Streaming Android App

It’s not difficult to create live streaming Android app that can record a video and send it to a server in real time. You can use do it by using javacv and they have a sample project for android. The sample project still works even though …

Use eq in mockito

When using mockito, we should use eq for String. It seems that we should use eq even for long. If we foget to use it as follows: when(mockService.method(longValue, any(ClassA.class))).thenReturn(true); You will get the following error. org…

RGB <-> YUV

As I wrote in this post, a video consists of a sequence of frames and a frame consists of pixels. A pixel is represented by color. Color has various forms of its representation, which is called color space. The most popular color space is …

Write a code to edit a video

As I wrote in this post, a image data is usually compressed. You need to decode (uncompressed) it, when you edit a video. Because you cannot access a frame without decoding(uncompress) it. ffmpeg enables you to access a frame easily by tak…

Video Streaming Protocol

In this post, I wrote about video file format and video code. When you want to do live streaming, you need to know video streaming protocols. You can upload a video as a file (flv, mp4 gif). However you cann’t download it after finishing u…

How we can store an image or video digitally

ffmpeg is a well known command line tool that allow you to edit videos. You can edit not only a video file but also a video stream. Probably its main function is to convert video format/codec. There are many video codes and formats. But wh…

Streaming Server Comparison

My colleagues and I made an app that can do live streaming with style-transfer filter. (its repo) last year. I did some research about streaming servers. WOWZA A widely-used commercial streaming server. It’s not free since it’s a commercia…

Java Implementation for enumerating pairings in Round-robin tournament

I made a code to enumerate pairings in Round-robin tournament. nakaly.hatenablog.com And I found better algorithm written in Ruby. nakaly.hatenablog.com I ported it to Java. gist.github.com

Private static field in Java interface

You cann't have a private static field in Java interface even though you use Java8 which you can have default implementation. There is a hack for this. public interface InterfaceContainsPrivateStaticFields { class _PrivateStaticFields { pr…

New DNS record propagation

DNS records are cached within TTL. That's why it takes time to see the change when you update a DNS record. Even if you add a new record in DNS, you may need wait for some time to see the new record. It may be caused by DNS master-slave re…