Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Wasserstein逆FM音源

Fadis
March 18, 2021

 Wasserstein逆FM音源

逆FM音源はWasserstein距離を誤差関数に使うと良い、という話をします
これは2021年3月20日に行われた Kernel/VM探検隊online part2での発表資料です
サンプルコード: https://github.com/Fadis/wifm

Fadis

March 18, 2021
Tweet

More Decks by Fadis

Other Decks in Programming

Transcript

  1. asserstein ٯFMԻݯ NAOMASA MATSUBAYASHI Twitter: @fadis_ WASSERSTEIN INVERTED FREQUENCY MODULATION

    SYNTHESIZER https://github.com/Fadis/wifm αϯϓϧίʔυ W ݱࡏςετԻ੠Λ࠶ੜ͍ͯ͠·͢ɻԻ͸ฉ͍͑ͯ͜·͔͢
  2. f (t) = Ec (t) sin (2πωc t + Em

    (t) B sin (2πωm t)) ͜ͷαΠϯ೾Ͱ ͜ͷαΠϯ೾Λ࿪ΊΔ FMԻݯ
  3. 1ωc = ωm 2ωc = ωm 3ωc = ωm 4ωc

    = ωm 5ωc = ωm f (t) = Ec (t) sin (2πωc t + Em (t) B sin (2πωm t)) 6ωc = ωm ύϥϝʔλʹΑͬͯ ༷ʑͳप೾਺ʹ༷ʑͳେ͖͞ͷഒԻ͕ग़Δ
  4. f (t) = Ec (t) sin (2πωc t + Em

    (t) B sin (2πωm t)) ͜Ε ͜Ε ͜Ε ͜Ε ͜Ε΋ ͜ΕΒͷύϥϝʔλΛௐ੔ͯ͠ ຊ෺ͷָثͱಉ͡ഒԻΛ࣋ͭԻΛग़ͤΕ͹ ͦͷָثͷԻʹฉ͑͜Δ
  5. ͜ΕΒͷύϥϝʔλΛௐ੔ͯ͠ ຊ෺ͷָثͱಉ͡ഒԻΛ࣋ͭԻΛग़ͤΕ͹ ͦͷָثͷԻʹฉ͑͜Δ f (t) = Ec (t) sin (2πωc

    t + Em (t) B sin (2πωm t)) ೉ FMԻݯ͸໓Μͩ ͜Ε ͜Ε ͜Ε ͜Ε ͜Ε΋ ͋·Γྑ͍Ի͕ग़ͳ͍ͱ͞Ε
  6. αϯϓϦϯάԻΛप೾਺ղੳ ϥϯμϜͳҨ఻ࢠΛੜ੒ ֤Ҩ఻ࢠΛ'.ԻݯͰԋ૗ ֤Ҩ఻ࢠͷԻΛप೾਺ղੳ Ұ༷ަ伹ͱಥવมҟͰҨ఻ࢠΛੜ੒ αϯϓϦϯάԻͱͷڑ཭Λܭࢉ ϧʔϨοτબ୒ͰݸମΛݫબ ࠷େ෼ղೳͰ ্ҐʹมԽ͕ݟΒΕͳ͍ ͸͍

    ͍͍͑ ෼ղೳΛ্͛Δ͔Ͳ͏͔Λ൑அ Ҩ఻తFMԻݯ 2016೥ https://speakerdeck.com/fadis/yi-chuan-de-fmyin-yuan Ҩ఻తΞϧΰϦζϜͰ ΑΓ༩͑ΒΕͨԻͷεϖΫτϧʹ ͍ۙԻʹͳΔύϥϝʔλΛ ੜଘͤ͞Δ ୈ12ճ ΧʔωϧʗVM୳ݕୂ
  7. https://speakerdeck.com/fadis/niyurarufmyin-yuan ٯFMԻݯ 2020೥ FMԻݯͷࣜΛඍ෼ͯ͠ ޯ഑๏ͰύϥϝʔλΛൃݟ͢Δ f (t) = A ∞

    ∑ n=−∞ Jn (B) cos (2πt (nωm + ωc)) Χʔωϧ7.୳ݕୂ!ؔ੢ճ໨ dJn (x) dx = 1 2 (Jn−1 (x) − Jn+1 (x))
  8. 261.63Hz 523.25Hz 784.88Hz 1046.5Hz 1308.1Hz 1569.8Hz 1831.4Hz 2093.0Hz 2354.6Hz ഒԻ͸੔਺ഒͷप೾਺෇ۙʹग़Δ

    άϥϯυϐΞϊ ΞϧταοΫε ϏϒϥϑΥϯ όΠΦϦϯ ϚϦϯό ͸ৗʹ੔਺ʹͳΔ͜ͱʹ͢Δ ω = ωm ωc
  9. ฏۉೋ৐ޡࠩ L = 1 n n ∑ i=0 (ei −

    gi) 2 ຊ෺ͷप೾਺੒෼ ੜ੒෺ͷप೾਺੒෼ શͯͷप೾਺੒෼ʹ͍ͭͯͷޡࠩΛ଍ͯ͠ฏۉΛऔΔ ຊ෺ͱੜ੒෺ͷ͕ࠩ ਖ਼Ͱ΋ෛͰ΋ޡࠩ͸ਖ਼ʹͳΔ ͱ ͕ࣅ͍ͯΔఔ ͸খ͘͞ͳΔ e g L ٯFMԻݯͷଛࣦؔ਺
  10. L = 1 n n ∑ i=0 (ei − gi)

    2 ฏۉೋ৐ޡ͕ࠩԻ৭ಉ࢜ͷڑ཭ΛଌΔखஈͱͯ͠ద͍ͯ͠ͳ͍ࣄ͸໌Β͔
  11. Wassersteinڑ཭ W (ℙ, ℚ) = inf J∈𝒥(ℙ, ℚ) ∫ ∥x

    − y∥dJ (x, y) ຊ෺ͷ෼෍ ੜ੒෺ͷ෼෍ ͷ͋Δαϯϓϧ͔Β ͷ͋Δαϯϓϧ΁ͷڑ཭ ℙ ℚ ࠷΋ޮ཰ͷྑ͍༌ૹํ๏Λ༻͍ͨ৔߹ͷ 2ͭͷ෼෍ͷྨࣅ౓ΛଌΔڑ཭ ͷ͋Δαϯϓϧ͔Β ͷ͋Δαϯϓϧ΁ͷ༌ૹྔ ℙ ℚ ༌ૹྔ ڑ཭ͷ૯࿨ ×
  12. Wassersteinڑ཭ 0 0.25 0.5 0.75 1 0 1 2 3

    4 5 0 0.25 0.5 0.75 1 0 1 2 3 4 5 ℙ ℚ W (ℙ, ℚ) = × 1+ × 1+ × 2 ͷঢ়ଶ͔Β ͷঢ়ଶʹ͢Δҝʹ ӡ͹ͳ͚Ε͹ͳΒͳ͍෺ ӡͿڑ཭ ͷ૯࿨ ℙ ℚ × ͜ͷ஋͕খ͍͞ఔ2ͭͷ෼෍͸ࣅ͍ͯΔͱݴ͑Δ
  13. ਺ֶతʹͪΌΜͱͨ͠આ໌΍ޮ཰ͷྑ͍ٻΊํ http://www.stat.cmu.edu/~larry/=sml/ 36-708 Statistical Methods for Machine Learning (CMUͷߨٛ)ͷࢿྉ ͱ͔

    https://arxiv.org/abs/1701.07875 Arjovsky, Martin, Soumith Chintala, and Léon Bottou. "Wasserstein generative adversarial networks." International conference on machine learning. PMLR, 2017. Wasserstein GAN Wassersteinڑ཭Λ࢖ͬͯϞʔυ่յΛ๷͙GANʹ͍ͭͯͷ࿦จ Optimal Transport and Wasserstein Distance ͋ͨΓݟͯ
  14. std::tuple< std::vector< T >, std::vector< T > > backward( const

    std::vector<T> &A, const std::vector<T> &AWeights, const std::vector<T> &B, const std::vector<T> &BWeights, T dist, T delta, T wdelta ) { std::vector<T> dAWeights( AWeights.size() ); std::vector<T> dA( A.size() ); #pragma omp parallel for for( size_t i = 0; i < A.size(); ++i ) { auto modif_ = A; modif_[ i ] += delta; auto modified_dist = forward_x( modif_, AWeights, B, BWeights ); dA[ i ] = ( modified_dist - dist ) / delta; } #pragma omp parallel for for( size_t i = 0; i < AWeights.size(); ++i ) { auto modif_ = AWeights; modif_[ i ] += wdelta; auto modified_dist = forward_x( A, modif_, B, BWeights ); dAWeights[ i ] = ( modified_dist - dist ) / wdelta; } return std::make_tuple( dA, dAWeights ); } ղੳతʹඍ෼Ͱ͖ͳ͍ͳΒ ਺஋తʹඍ෼͢Ε͹ྑ͍
  15. $ time wav2fm2 -i Piano.ff.C4.aiff -d 1 -n 60 -t

    40 ... real 4m43.748s user 17m5.382s sys 0m3.239s $ time wav2fm -i Piano.ff.C4.aiff -d 1 -n 60 ... real 3m27.189s user 3m29.071s sys 0m0.036s ٯFMԻݯͰϐΞϊͷύϥϝʔλΛ୳͢ WassersteinٯFMԻݯͰϐΞϊͷύϥϝʔλΛ୳͢ ΍͸Γ਺஋ඍ෼͸஗͍ Intel Core i5-6500 (Gentoo Linux)Λ࢖༻
  16. Sinkhorn Distances: Lightspeed Computation of Optimal Transport Cuturi, Marco. "Sinkhorn

    distances: lightspeed computation of optimal transport." NIPS. Vol. 2. No. 3. 2013. https://papers.nips.cc/paper/2013/hash/af21d0c97db2e27e13572cbf59eb343d- Abstract.html Wassersteinڑ཭ͷۙࣅ Differential Properties of Sinkhorn Approximation for Learning with Wasserstein Distance Luise, Giulia, et al. "Differential properties of sinkhorn approximation for learning with wasserstein distance." arXiv preprint arXiv:1805.11897 (2018). Wassersteinڑ཭ͷۙࣅͷඍ෼ https://arxiv.org/abs/1805.11897 ্ख͘΍Ε͹͜ͷ΁Μ͕࢖͑Δ͔΋