2016년 12월 25일 일요일

[C#] collection, Array

IEnumerable : 최소한의 기능성 (열거) 만 제공. Movenext로 값 찾는다. 인덱스로 못찾음.

ICollection : 중간정도 기능성 . 카운트같은것.

IList / IDictionary : 최대의 기능성 . 색인 키에 의한 임의접근도 가능 

IEnumerable - Movenext, foreach의 기능이 있다 .

ICollection - IEnumerable과 같이 foreach로 항목을 훑는기능에 count, Contain, ToArray 기능 + 쓰기 가능한것에는 Add,Remove,clear 기능이 있다. 

IList - 특정 위치의 요소에 접근하는 기능이 있다.



** ArrayList 는 List 보다 느리다. (T가 값형식 일때)
// Array //
Array 는 크기는 변경이 안된다. 하지만 색인으로 특정 요소에 접근하는 속도는 매우 빠르다.

참조 형식이라 딥카피를 해야한다. (Array1 = Array2.Clone() 이건 shallow copy다 )

열거 - Array.ForEach(new[] {1,2,3} , console.WriteLine);

BitArray - bool 값만 저장하므로, 메모리사용이 적다. 0

하드디스크 타입별 최대 파일 용량 크기

  • NTFS: 16 TiB - 64 KiB
  • Ext4: 16 TBs
  • FAT32: 4GB - 1

2016년 12월 22일 목요일

[python] matplotlib setting

backend 를 다음에서 정할 수 있다 . 경로는

C:\Anaconda2\Lib\site-packages\matplotlib\mpl-data\matplotlibrc

# The default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# CocoaAgg MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
# Template.
# You can also deploy your own backend outside of matplotlib by
# referring to the module name (which must be in the PYTHONPATH) as
# 'module://my_backend'.
backend      : WXAgg <

# If you are using the Qt4Agg backend, you can choose here
# to use the PyQt4 bindings or the newer PySide bindings to
# the underlying Qt4 toolkit.
backend.qt4 : PyQt4 <

2016년 12월 19일 월요일

[python] Theano Givens

from theano import function
from theano import tensor as T
from theano import shared

state = shared(0)
inc = T.iscalar()
accumulator = function([inc],state,updates=[(state,state+inc)])
decrementor = function([inc],state,updates=[(state,state-inc)])

fn_of_state = state*2+inc
foo = T.scalar(dtype=state.dtype)
skip_shared = function([inc,foo],fn_of_state,givens=[(state,foo)])

print state.get_value()
print skip_shared(1,3)

----------------------------------------------------------------------
givens=[(state,foo)]은 state를 foo로 대체해준다.

따라서, inc =1 , foo= 3 이였고, given으로 state를 foo즉 3으로 바꿔서 fn_of_state가 계산된다.

그리고 원래의 state는 바뀌지 안는다.

이 givens는 shared valuable뿐만 아니라, 모든 심볼릭 변수들을 대체할 수 있다.

[Python] Theano Shared Variable and update

from theano import function
from theano import tensor as T
from theano import shared

state = shared(0)
inc = T.iscalar()
accumulator = function([inc],state,update=[(state,state+inc)])

---------------------------------------------------------------------------
여기서 이 shared value 는 전역 변수라고 생각하면 된다.

이 변수를 사용하는 모든 함수는 이 값을 공유하게 된다.

이 값은 접근을 아래와 같이 한다.

The value can be accessed and modified by the .get_value() and .set_value() method

---------------------------------------------------------------------------
여기서 update 는 어떤 형태(form)의 페어에 적용이 된다.

즉,  state.value 를 state_inc로 바꾼다 라는 의미가 된다.


===============================================
이 코드의 의미를 살펴보자.
state 는 shared  변수
inc는 일반적인 변수이다.

accumulator 는 input 으로 inc변수 (iscalar) 를 가지고, output으로는 stsate 를 내보낸다.
그리고 이 함수는 state를 state+inc로 바꾸는 동작을 가진 함수이다.

따라서 accumulator(K) 를 실행하면,output으로 stsate를 출력후  state 를 stsate_inc로 바꾼다.


**  update 를 쓰는 이유.
1.가끔 더 속도가 빠름.
2. 언제 업데이트 되는지 추적을 편하게 하기 위해.
3. shared variable를 사용을 안하는데, 업데이트는 해야될떄

2016년 12월 5일 월요일

[c#] Function Factory 예제


스트림 바이트별로 읽는 함수

------

public Dictionary> ReaderDict( Stream stream )
        {
            Dictionary < string, Func > output = new Dictionary>();

            Func readbytearr =  input  =>
            {
                stream.Read(input,0,input.Length);
                return input;
            };

            Func ToByte     = () => (byte)stream.ReadByte();
            Func ToInt      = () => BitConverter.ToInt32 ( readbytearr(new byte[4]),0 );
            Func ToLong     = () => BitConverter.ToInt64 ( readbytearr(new byte[8]),0 );
            Func ToFloat    = () => BitConverter.ToSingle( readbytearr(new byte[4]),0 );

            byte[] tempman = new byte[2];

            output.Add( "byte" , ToByte );
            output.Add( "int" , ToInt );
            output.Add( "long" , ToLong );
            output.Add( "float" , ToFloat );

            return output;
        }

-------

읽는 예제가 (reader 는 위의 읽는 딕셔너리 이름)
for ( int i = 0 ; i < 3 ; i++ )
            {
                Console.WriteLine( "X"           +"="+ reader["int"]() );
                Console.WriteLine( "Y"           +"="+ reader["int"]() );
                Console.WriteLine( "ByteOffset"  +"="+ reader["long"]() );
                Console.WriteLine( "Length"      +"="+ reader["int"]());
                Console.WriteLine( "Width"       +"="+ reader["int"]());
                Console.WriteLine( "Height"      +"="+ reader["int"]() );
                Console.WriteLine( "RealX"       +"="+ reader["float"]());
                Console.WriteLine( "RealY"       +"="+ reader["float"]());
                Console.WriteLine( "RealW"       +"="+ reader["float"]());
                Console.WriteLine( "RealH"       +"="+ reader["float"]() );
                Console.ReadLine();
            }