summaryrefslogtreecommitdiffstats
path: root/contrib/lua-torch/optim/ConfusionMatrix.lua
blob: ec5302c24dd17db02721a7f774b18d75e2446879 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
--[[ A Confusion Matrix class

Example:

    conf = optim.ConfusionMatrix( {'cat','dog','person'} )   -- new matrix
    conf:zero()                                              -- reset matrix
    for i = 1,N do
        conf:add( neuralnet:forward(sample), label )         -- accumulate errors
    end
    print(conf)                                              -- print matrix
    image.display(conf:render())                             -- render matrix
]]
local ConfusionMatrix = torch.class('optim.ConfusionMatrix')

function ConfusionMatrix:__init(nclasses, classes)
   if type(nclasses) == 'table' then
      classes = nclasses
      nclasses = #classes
   end
   self.mat = torch.LongTensor(nclasses,nclasses):zero()
   self.valids = torch.FloatTensor(nclasses):zero()
   self.unionvalids = torch.FloatTensor(nclasses):zero()
   self.nclasses = nclasses
   self.totalValid = 0
   self.averageValid = 0
   self.classes = classes or {}
   -- buffers
   self._mat_flat = self.mat:view(-1)
   self._target = torch.FloatTensor()
   self._prediction = torch.FloatTensor()
   self._max = torch.FloatTensor()
   self._pred_idx = torch.LongTensor()
   self._targ_idx = torch.LongTensor()
end

-- takes scalar prediction and target as input
function ConfusionMatrix:_add(p, t)
   assert(p and type(p) == 'number')
   assert(t and type(t) == 'number')
   -- non-positive values are considered missing
   -- and therefore ignored
   if t > 0 then
      self.mat[t][p] = self.mat[t][p] + 1
   end
end

function ConfusionMatrix:add(prediction, target)
   if type(prediction) == 'number' then
      -- comparing numbers
      self:_add(prediction, target)
   else
      self._prediction:resize(prediction:size()):copy(prediction)
      assert(prediction:dim() == 1)
      if type(target) == 'number' then
         -- prediction is a vector, then target assumed to be an index
         self._max:max(self._pred_idx, self._prediction, 1)
         self:_add(self._pred_idx[1], target)
      else
         -- both prediction and target are vectors
         assert(target:dim() == 1)
         self._target:resize(target:size()):copy(target)
         self._max:max(self._targ_idx, self._target, 1)
         self._max:max(self._pred_idx, self._prediction, 1)
         self:_add(self._pred_idx[1], self._targ_idx[1])
      end
   end
end

function ConfusionMatrix:batchAdd(predictions, targets)
   local preds, targs, __
   self._prediction:resize(predictions:size()):copy(predictions)
   if predictions:dim() == 1 then
      -- predictions is a vector of classes
      preds = self._prediction
   elseif predictions:dim() == 2 then
      -- prediction is a matrix of class likelihoods
      if predictions:size(2) == 1 then
         -- or prediction just needs flattening
         preds = self._prediction:select(2,1)
      else
         self._max:max(self._pred_idx, self._prediction, 2)
         preds = self._pred_idx:select(2,1)
      end
   else
      error("predictions has invalid number of dimensions")
   end

   self._target:resize(targets:size()):copy(targets)
   if targets:dim() == 1 then
      -- targets is a vector of classes
      targs = self._target
   elseif targets:dim() == 2 then
      -- targets is a matrix of one-hot rows
      if targets:size(2) == 1 then
         -- or targets just needs flattening
         targs = self._target:select(2,1)
      else
         self._max:max(self._targ_idx, self._target, 2)
         targs = self._targ_idx:select(2,1)
      end
   else
      error("targets has invalid number of dimensions")
   end

   -- non-positive values are considered missing and therefore ignored
   local mask = targs:ge(1)
   targs = targs[mask]
   preds = preds[mask]

   self._mat_flat = self._mat_flat or self.mat:view(-1) -- for backward compatibility

   preds = preds:typeAs(targs)

   assert(self.mat:isContiguous() and self.mat:stride(2) == 1)
   local indices = ((targs - 1) * self.mat:stride(1) + preds):typeAs(self.mat)
   local ones = torch.ones(1):typeAs(self.mat):expand(indices:size(1))
   self._mat_flat:indexAdd(1, indices, ones)
end

function ConfusionMatrix:zero()
   self.mat:zero()
   self.valids:zero()
   self.unionvalids:zero()
   self.totalValid = 0
   self.averageValid = 0
end

local function isNaN(number)
  return number ~= number
end

function ConfusionMatrix:updateValids()
   local total = 0
   for t = 1,self.nclasses do
      self.valids[t] = self.mat[t][t] / self.mat:select(1,t):sum()
      self.unionvalids[t] = self.mat[t][t] / (self.mat:select(1,t):sum()+self.mat:select(2,t):sum()-self.mat[t][t])
      total = total + self.mat[t][t]
   end
   self.totalValid = total / self.mat:sum()
   self.averageValid = 0
   self.averageUnionValid = 0
   local nvalids = 0
   local nunionvalids = 0
   for t = 1,self.nclasses do
      if not isNaN(self.valids[t]) then
         self.averageValid = self.averageValid + self.valids[t]
         nvalids = nvalids + 1
      end
      if not isNaN(self.valids[t]) and not isNaN(self.unionvalids[t]) then
         self.averageUnionValid = self.averageUnionValid + self.unionvalids[t]
         nunionvalids = nunionvalids + 1
      end
   end
   self.averageValid = self.averageValid / nvalids
   self.averageUnionValid = self.averageUnionValid / nunionvalids
end

-- Calculating FAR/FRR associated with the confusion matrix

function ConfusionMatrix:farFrr()
   local cmat = self.mat
   local noOfClasses = cmat:size()[1]
   self._frrs = self._frrs or torch.zeros(noOfClasses)
   self._frrs:zero()
   self._classFrrs = self._classFrrs or torch.zeros(noOfClasses)
   self._classFrrs:zero()
   self._classFrrs:add(-1)
   self._fars = self._fars or torch.zeros(noOfClasses)
   self._fars:zero()
   self._classFars = self._classFars or torch.zeros(noOfClasses)
   self._classFars:zero()
   self._classFars:add(-1)
   local classSamplesCount = cmat:sum(2)
   local indx = 1
   for i=1,noOfClasses do
      if classSamplesCount[i][1] ~= 0 then
         self._frrs[indx] = 1 - cmat[i][i]/classSamplesCount[i][1]
         self._classFrrs[i] = self._frrs[indx]
         -- Calculating FARs
         local farNumerator = 0
         local farDenominator = 0
         for j=1, noOfClasses do
            if i ~= j then
               if classSamplesCount[j][1] ~= 0 then
                  farNumerator = farNumerator + cmat[j][i]/classSamplesCount[j][1]
                  farDenominator  = farDenominator + 1
               end
            end
         end
         self._fars[indx] = farNumerator/farDenominator
         self._classFars[i] = self._fars[indx]
         indx = indx + 1
      end
   end
   indx = indx - 1
   local returnFrrs = self._frrs[{{1, indx}}]
   local returnFars = self._fars[{{1, indx}}]
   return self._classFrrs, self._classFars, returnFrrs, returnFars
end

local function log10(n)
   if math.log10 then
      return math.log10(n)
   else
      return math.log(n) / math.log(10)
   end
end

function ConfusionMatrix:__tostring__()
   self:updateValids()
   local str = {'ConfusionMatrix:\n'}
   local nclasses = self.nclasses
   table.insert(str, '[')
   local maxCnt = self.mat:max()
   local nDigits = math.max(8, 1 + math.ceil(log10(maxCnt)))
   for t = 1,nclasses do
      local pclass = self.valids[t] * 100
      pclass = string.format('%2.3f', pclass)
      if t == 1 then
         table.insert(str, '[')
      else
         table.insert(str, ' [')
      end
      for p = 1,nclasses do
         table.insert(str, string.format('%' .. nDigits .. 'd', self.mat[t][p]))
      end
      if self.classes and self.classes[1] then
         if t == nclasses then
            table.insert(str, ']]  ' .. pclass .. '% \t[class: ' .. (self.classes[t] or '') .. ']\n')
         else
            table.insert(str, ']   ' .. pclass .. '% \t[class: ' .. (self.classes[t] or '') .. ']\n')
         end
      else
         if t == nclasses then
            table.insert(str, ']]  ' .. pclass .. '% \n')
         else
            table.insert(str, ']   ' .. pclass .. '% \n')
         end
      end
   end
   table.insert(str, ' + average row correct: ' .. (self.averageValid*100) .. '% \n')
   table.insert(str, ' + average rowUcol correct (VOC measure): ' .. (self.averageUnionValid*100) .. '% \n')
   table.insert(str, ' + global correct: ' .. (self.totalValid*100) .. '%')
   return table.concat(str)
end

function ConfusionMatrix:render(sortmode, display, block, legendwidth)
   -- args
   local confusion = self.mat:double()
   local classes = self.classes
   local sortmode = sortmode or 'score' -- 'score' or 'occurrence'
   local block = block or 25
   local legendwidth = legendwidth or 200
   local display = display or false

   -- legends
   local legend = {
      ['score'] = 'Confusion matrix [sorted by scores, global accuracy = %0.3f%%, per-class accuracy = %0.3f%%]',
      ['occurrence'] = 'Confusion matrix [sorted by occurrences, accuracy = %0.3f%%, per-class accuracy = %0.3f%%]'
   }

   -- parse matrix / normalize / count scores
   local diag = torch.FloatTensor(#classes)
   local freqs = torch.FloatTensor(#classes)
   local unconf = confusion
   local confusion = confusion:clone()
   local corrects = 0
   local total = 0
   for target = 1,#classes do
      freqs[target] = confusion[target]:sum()
      corrects = corrects + confusion[target][target]
      total = total + freqs[target]
      confusion[target]:div( math.max(confusion[target]:sum(),1) )
      diag[target] = confusion[target][target]
   end

   -- accuracies
   local accuracy = corrects / total * 100
   local perclass = 0
   local total = 0
   for target = 1,#classes do
      if confusion[target]:sum() > 0 then
         perclass = perclass + diag[target]
         total = total + 1
      end
   end
   perclass = perclass / total * 100
   freqs:div(unconf:sum())

   -- sort matrix
   if sortmode == 'score' then
      _,order = torch.sort(diag,1,true)
   elseif sortmode == 'occurrence' then
      _,order = torch.sort(freqs,1,true)
   else
      error('sort mode must be one of: score | occurrence')
   end

   -- render matrix
   local render = torch.zeros(#classes*block, #classes*block)
   for target = 1,#classes do
      for prediction = 1,#classes do
         render[{ { (target-1)*block+1,target*block }, { (prediction-1)*block+1,prediction*block } }] = confusion[order[target]][order[prediction]]
      end
   end

   -- add grid
   for target = 1,#classes do
      render[{ {target*block},{} }] = 0.1
      render[{ {},{target*block} }] = 0.1
   end

   -- create rendering
   require 'image'
   require 'qtwidget'
   require 'qttorch'
   local win1 = qtwidget.newimage( (#render)[2]+legendwidth, (#render)[1] )
   image.display{image=render, win=win1}

   -- add legend
   for i in ipairs(classes) do
      -- background cell
      win1:setcolor{r=0,g=0,b=0}
      win1:rectangle((#render)[2],(i-1)*block,legendwidth,block)
      win1:fill()

      -- %
      win1:setfont(qt.QFont{serif=false, size=fontsize})
      local gscale = freqs[order[i]]/freqs:max()*0.9+0.1 --3/4
      win1:setcolor{r=gscale*0.5+0.2,g=gscale*0.5+0.2,b=gscale*0.8+0.2}
      win1:moveto((#render)[2]+10,i*block-block/3)
      win1:show(string.format('[%2.2f%% labels]',math.floor(freqs[order[i]]*10000+0.5)/100))

      -- legend
      win1:setfont(qt.QFont{serif=false, size=fontsize})
      local gscale = diag[order[i]]*0.8+0.2
      win1:setcolor{r=gscale,g=gscale,b=gscale}
      win1:moveto(120+(#render)[2]+10,i*block-block/3)
      win1:show(classes[order[i]])

      for j in ipairs(classes) do
         -- scores
         local score = confusion[order[j]][order[i]]
         local gscale = (1-score)*(score*0.8+0.2)
         win1:setcolor{r=gscale,g=gscale,b=gscale}
         win1:moveto((i-1)*block+block/5,(j-1)*block+block*2/3)
         win1:show(string.format('%02.0f',math.floor(score*100+0.5)))
      end
   end

   -- generate tensor
   local t = win1:image():toTensor()

   -- display
   if display then
      image.display{image=t, legend=string.format(legend[sortmode],accuracy,perclass)}
   end

   -- return rendering
   return t
end
/option> Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
summaryrefslogtreecommitdiffstats
path: root/settings/l10n/ja_JP.php
blob: 2fbe05befa9fe7aaaf45bfa85ab7719e14ebc404 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
$TRANSLATIONS = array(
"Unable to load list from App Store" => "アプリストアからリストをロードできません",
"Authentication error" => "認証エラー",
"Your display name has been changed." => "表示名を変更しました。",
"Unable to change display name" => "表示名を変更できません",
"Group already exists" => "グループは既に存在しています",
"Unable to add group" => "グループを追加できません",
"Could not enable app. " => "アプリを有効にできませんでした。",
"Email saved" => "メールアドレスを保存しました",
"Invalid email" => "無効なメールアドレス",
"Unable to delete group" => "グループを削除できません",
"Unable to delete user" => "ユーザを削除できません",
"Language changed" => "言語が変更されました",
"Invalid request" => "不正なリクエスト",
"Admins can't remove themself from the admin group" => "管理者は自身を管理者グループから削除できません。",
"Unable to add user to group %s" => "ユーザをグループ %s に追加できません",
"Unable to remove user from group %s" => "ユーザをグループ %s から削除できません",
"Couldn't update app." => "アプリを更新出来ませんでした。",
"Update to {appversion}" => "{appversion} に更新",
"Disable" => "無効",
"Enable" => "有効化",
"Please wait...." => "しばらくお待ちください。",
"Error" => "エラー",
"Updating...." => "更新中....",
"Error while updating app" => "アプリの更新中にエラーが発生",
"Updated" => "更新済み",
"Saving..." => "保存中...",
"deleted" => "削除",
"undo" => "元に戻す",
"Unable to remove user" => "ユーザを削除出来ません",
"Groups" => "グループ",
"Group Admin" => "グループ管理者",
"Delete" => "削除",
"add group" => "グループを追加",
"A valid username must be provided" => "有効なユーザ名を指定する必要があります",
"Error creating user" => "ユーザ作成エラー",
"A valid password must be provided" => "有効なパスワードを指定する必要があります",
"__language_name__" => "Japanese (日本語)",
"Security Warning" => "セキュリティ警告",
"Your data directory and your files are probably accessible from the internet. The .htaccess file is not working. We strongly suggest that you configure your webserver in a way that the data directory is no longer accessible or you move the data directory outside the webserver document root." => "データディレクトリとファイルがインターネットからアクセス可能になっている可能性があります。.htaccessファイルが機能していません。データディレクトリがアクセスされないようにウェブサーバーを設定するか、ウェブサーバーのドキュメントルートからデータディレクトリを移動するように強くお勧めします。",
"Setup Warning" => "セットアップ警告",
"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "WebDAVインタフェースが動作していないと考えられるため、あなたのWEBサーバはまだファイルの同期を許可するように適切な設定がされていません。",
"Please double check the <a href=\"%s\">installation guides</a>." => "<a href=\"%s\">installation guides</a>をもう一度チェックするようにお願いいたします。",
"Module 'fileinfo' missing" => "モジュール 'fileinfo' が見つかりません",
"The PHP module 'fileinfo' is missing. We strongly recommend to enable this module to get best results with mime-type detection." => "PHP のモジュール 'fileinfo' が見つかりません。mimeタイプの検出を精度良く行うために、このモジュールを有効にすることを強くお勧めします。",
"Locale not working" => "ロケールが動作していません",
"System locale can't be set to %s. This means that there might be problems with certain characters in file names. We strongly suggest to install the required packages on your system to support %s." => "システムロケールが %s に設定出来ません。この場合、ファイル名にそのロケールの文字が入っていたときに問題になる可能性があります。必要なパッケージをシステムにインストールして、%s をサポートすることを強くお勧めします。",
"Internet connection not working" => "インターネット接続が動作していません",
"This server has no working internet connection. This means that some of the features like mounting of external storage, notifications about updates or installation of 3rd party apps don´t work. Accessing files from remote and sending of notification emails might also not work. We suggest to enable internet connection for this server if you want to have all features." => "このサーバーはインターネットに接続していません。この場合、外部ストレージのマウント、更新の通知やサードパーティアプリといったいくつかの機能が使えません。また、リモート接続でのファイルアクセス、通知メールの送信と言った機能も利用できないかもしれません。全ての機能を利用したいのであれば、このサーバーからインターネットに接続できるようにすることをお勧めします。",
"Cron" => "Cron",
"Execute one task with each page loaded" => "各ページの読み込み時にタスクを実行する",
"cron.php is registered at a webcron service to call cron.php once a minute over http." => "http経由で1分間に1回cron.phpを呼び出すように cron.phpがwebcron サービスに登録されています。",
"Use systems cron service to call the cron.php file once a minute." => "cron.phpファイルを1分間に1回実行する為にサーバーのcronサービスを利用する。",
"Sharing" => "共有",
"Enable Share API" => "共有APIを有効にする",
"Allow apps to use the Share API" => "アプリからの共有APIの利用を許可する",
"Allow links" => "リンクを許可する",
"Allow users to share items to the public with links" => "リンクによりアイテムを公開することを許可する",
"Allow public uploads" => "パブリックなアップロードを許可",
"Allow users to enable others to upload into their publicly shared folders" => "公開している共有フォルダへのアップロードを共有しているメンバーにも許可",
"Allow resharing" => "再共有を許可する",
"Allow users to share items shared with them again" => "ユーザが共有しているアイテムの再共有を許可する",
"Allow users to share with anyone" => "ユーザが誰とでも共有することを許可する",
"Allow users to only share with users in their groups" => "ユーザにグループ内のユーザとのみ共有を許可する",
"Security" => "セキュリティ",
"Enforce HTTPS" => "常にHTTPSを使用する",
"Forces the clients to connect to %s via an encrypted connection." => "クライアントから %sへの接続を常に暗号化する。",
"Please connect to your %s via HTTPS to enable or disable the SSL enforcement." => "強制的なSSL接続を有効/無効にするために、HTTPS経由で %s へ接続してください。",
"Log" => "ログ",
"Log level" => "ログレベル",
"More" => "もっと見る",
"Less" => "閉じる",
"Version" => "バージョン",
"Developed by the <a href=\"http://ownCloud.org/contact\" target=\"_blank\">ownCloud community</a>, the <a href=\"https://github.com/owncloud\" target=\"_blank\">source code</a> is licensed under the <a href=\"http://www.gnu.org/licenses/agpl-3.0.html\" target=\"_blank\"><abbr title=\"Affero General Public License\">AGPL</abbr></a>." => "<a href=\"http://ownCloud.org/contact\" target=\"_blank\">ownCloud コミュニティ</a>により開発されています。 <a href=\"https://github.com/owncloud\" target=\"_blank\">ソースコード</a>は、<a href=\"http://www.gnu.org/licenses/agpl-3.0.html\" target=\"_blank\"><abbr title=\"Affero General Public License\">AGPL</abbr></a> ライセンスの下で提供されています。",
"Add your App" => "アプリを追加",
"More Apps" => "さらにアプリを表示",
"Select an App" => "アプリを選択してください",
"See application page at apps.owncloud.com" => "apps.owncloud.com でアプリケーションのページを見てください",
"<span class=\"licence\"></span>-licensed by <span class=\"author\"></span>" => "<span class=\"licence\"></span>-ライセンス: <span class=\"author\"></span>",
"Update" => "更新",
"User Documentation" => "ユーザドキュメント",
"Administrator Documentation" => "管理者ドキュメント",
"Online Documentation" => "オンラインドキュメント",
"Forum" => "フォーラム",
"Bugtracker" => "バグトラッカー",
"Commercial Support" => "コマーシャルサポート",
"Get the apps to sync your files" => "ファイルを同期するためのアプリを取得",
"Show First Run Wizard again" => "初回ウィザードを再表示する",
"You have used <strong>%s</strong> of the available <strong>%s</strong>" => "現在、<strong>%s</strong> / <strong>%s</strong> を利用しています",
"Password" => "パスワード",
"Your password was changed" => "パスワードを変更しました",
"Unable to change your password" => "パスワードを変更することができません",
"Current password" => "Current password",
"New password" => "新しいパスワードを入力",
"Change password" => "パスワードを変更",
"Display Name" => "表示名",
"Email" => "メール",
"Your email address" => "あなたのメールアドレス",
"Fill in an email address to enable password recovery" => "※パスワード回復を有効にするにはメールアドレスの入力が必要です",
"Language" => "言語",
"Help translate" => "翻訳に協力する",
"WebDAV" => "WebDAV",
"Use this address to <a href=\"%s/server/5.0/user_manual/files/files.html\" target=\"_blank\">access your Files via WebDAV</a>" => "<a href=\"%s/server/5.0/user_manual/files/files.html\" target=\"_blank\">WebDAV経由でファイルにアクセス</a>するにはこのアドレスを利用してください",
"Login Name" => "ログイン名",
"Create" => "作成",
"Admin Recovery Password" => "管理者復旧パスワード",
"Enter the recovery password in order to recover the users files during password change" => "パスワード変更の間のユーザーのファイルを回復するために、リカバリパスワードを入力してください",
"Default Storage" => "デフォルトストレージ",
"Unlimited" => "無制限",
"Other" => "その他",
"Username" => "ユーザー名",
"Storage" => "ストレージ",
"change display name" => "表示名を変更",
"set new password" => "新しいパスワードを設定",
"Default" => "デフォルト"
);
$PLURAL_FORMS = "nplurals=1; plural=0;";