11월, 2017의 게시물 표시

[Deep learning] Gradient Descent Optimizer

이미지
https://icim.nims.re.kr/post/easyMath/70 알기 쉬운 산업수학 알기 쉬운 산업수학 Gradient Descent Optimizer 2017년 12월 13일(수) | 김민중 URL  (1) 주어진 목적함수  f f 의 최솟값(minimum)을 찾아가는 알고리즘으로 다음과 같은 방식으로 최솟값을 찾아간다. 초기값  x 0 x 0 을 임의로 설정, 적당한 Learning rate  α α  설정 n ≥ 0 n ≥ 0 인 정수에 대해서  x n + 1 x n + 1 은 다음과 같이 정의한다. x n + 1 : = x n − α ⋅ ∇ f ( x n ) x n + 1 := x n − α ⋅ ∇ f ( x n ) 주의사항 함수 f f 의 모양이 convex가 아닌 경우 global minimum이 아닌 local minimum으로  x n x n 이 수렴할 가능성이 있다. Learning rate  α α  값이 큰 경우 최솟값으로  x n x n 이 수렴하는 것이 아니라 발산할 수 있다. Learning rate  α α  값이 작은 경우 수렴하는 속도가 지나치게 느릴 수 있다. 방정식  2 ⋅ x = 10 2 ⋅ x = 10  의 근을 Gradient Descent를 이용해서 찾아보자. 목적함수  f ( x ) : = ( 10 − 2 x ) 2 f ( x ) := ( 10 − 2 x ) 2 으로 설정하겠다( f f 의 최솟값인 0이 되게 하는  x x 값이 우리가 원하는 방정식의 근이다). 초기값  x 0 = 0 x 0 = 0 , Learning rate  α = 0.05 α = 0.05 으로 설정 f ′ ( x ) = 4 ( 2 x − 10 ) f ′ ( x ) = 4 ( 2 x − 10 )...

[Java][C++] String exchange

<How to exchange string with java and c++> Match string format with UTF8. <Solution> Java: String original = new String ( "BANANAS" ); byte [] utf8Bytes = original . getBytes ( "UTF8" ); //save the length as a 32 bit integer, then utf8 Bytes to a file C++: int32_t tlength ; std :: string utf8Bytes ; //load the tlength as a 32 bit integer, then the utf8 bytes from the file //well, that's easy for UTF8 //to turn that into a utf-18 string in windows int wlength = MultiByteToWideChar ( CP_UTF8 , 0 , utf8Bytes . c_str (), utf8Bytes . size (), nullptr , 0 ); std :: wstring result ( wlength , '\0' ); MultiByteToWideChar ( CP_UTF8 , 0 , utf8Bytes . c_str (), utf8Bytes . size (), & result [ 0 ], wlength ); //so that's not hard either <Reference> https://stackoverflow.com/questions/7438327/how-to-convert-java-string-to-c-string-using-bytes-as-the-medium

[Android] Android Read SQLite database From Assets Folder

Android Read SQLite database From Assets Folder Dharmendra Singh   February 2, 2017   0 In this tutorial you will learn,  how can you read SQLite Database from assets folder? Some times you have a SQLite database file and want to read in your app. So this tutorial explain you about it. In this example we need a .sqlite file and we put this file inside assets folder. Now lets start this example Create  activity_main.xml  file <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp"> <LinearLayout android:layout_wi...

[Android] Get External storage path

public class ExtSdCardHelper {     public static HashSet<String> getExternalMounts() {         final HashSet<String> out = new HashSet<String>();         String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";         String s = "";         try {             final Process process = new ProcessBuilder().command("mount")                     .redirectErrorStream(true).start();             process.waitFor();             final InputStream is = process.getInputStream();             final byte[] buffer = new byte[1024];             while (is.read(buffer) != -1) {                 s = s + new String(buffer);   ...

[Android][SQLite] DB to external storage

How to copy sqlite db to external storage from app. <Soluthion> private void copyDbToExternal ( Context context ) { try { File sd = Environment . getExternalStorageDirectory (); File data = Environment . getDataDirectory (); if ( sd . canWrite ()) { String currentDBPath = "//data//data//" + context . getApplicationContext (). getPackageName () + "//databases//" + DB_NAME ; String backupDBPath = DB_NAME ; File currentDB = new File ( data , currentDBPath ); File backupDB = new File ( sd , backupDBPath ); FileChannel src = new FileInputStream ( currentDB ). getChannel (); FileChannel dst = new FileOutputStream ( backupDB ). getChannel (); dst . transferFrom ( src , 0 , src . size ()); src . close (); dst . close (); } } catch ( Exception...