国内精品久久久久_亚洲区手机在线中文无码播放_国内精品久久久久影院一蜜桃_日韩内射激情视频在线播放免费

      全加器電路設(shè)計(jì)作用?

      時(shí)間:2024-09-18 12:29 人氣:0 編輯:招聘街

      一、全加器電路設(shè)計(jì)作用?

      全加器的邏輯功能是兩個(gè)同位的二進(jìn)制數(shù)及來(lái)自低位的進(jìn)位三者相加。

      全加器用門電路實(shí)現(xiàn)兩個(gè)二進(jìn)制數(shù)相加并求出和的組合線路,稱為一位全加器。一位全加器可以處理低位進(jìn)位,并輸出本位加法進(jìn)位。多個(gè)一位全加器進(jìn)行級(jí)聯(lián)可以得到多位全加器。常用二進(jìn)制四位全加器74LS283。

      二、門電路設(shè)計(jì)軟件?

      logisim是一款非常好用的電路設(shè)計(jì)軟件,它主要的功能是基于教育的數(shù)字邏輯電路設(shè)計(jì)模擬,使用這款軟件可以創(chuàng)建通俗易懂的電路圖,使用簡(jiǎn)單、便于學(xué)習(xí),擁有最基本的概念與邏輯電路!

      logisim軟件特色:

      這是免費(fèi)的!(Logisim開(kāi)源(GPL)。

      運(yùn)行在任何機(jī)器中支持Java5或更高的特殊MacOSX和Windows版本。的雙曲馀弦值。學(xué)生有跨平臺(tái)當(dāng)然是重要的家庭/宿舍計(jì)算機(jī)系統(tǒng)。

      畫面界面是基于直觀的工具欄。彩色電線有助于模擬和調(diào)試電路。

      自動(dòng)布線工具繪制橫縱電線,與其他電線連接組件。很容易畫電路!

      完成電路可以保存在文件中,出口到GIF文件或印刷在打印機(jī)上。

      電路布局可用作子回路回路,設(shè)計(jì)分層回路。

      包括電路組件包括輸入和輸出、蓋茨、多重復(fù)用器、算術(shù)電路、拖鞋和RAM內(nèi)存。

      包括組合分析模塊允許之間的轉(zhuǎn)換電路、真實(shí)價(jià)值表和邏輯表達(dá)。

      三、臥室床頭電路設(shè)計(jì)?

      床頭區(qū)域:床頭區(qū)域留有足夠的插孔,以免日后麻煩。首先是電話線插孔,要在床頭柜上方預(yù)留,并采用5孔插線板帶開(kāi)關(guān)為宜。然后還要預(yù)留足夠的插孔和開(kāi)關(guān),能控制各個(gè)區(qū)域的電路單獨(dú)開(kāi)閉。除此之外,不要忘記,如果雙床頭柜,對(duì)稱設(shè)置。

      梳妝區(qū)域:梳妝臺(tái)方上應(yīng)該預(yù)留一個(gè)能夠連接吹風(fēng)機(jī)的電源,此外梳妝鏡上方有反射燈,也應(yīng)設(shè)置一個(gè)單獨(dú)開(kāi)關(guān)控制。

      四、方塊電路設(shè)計(jì)步驟?

      打開(kāi)Altium Designer 18軟件中的原理圖設(shè)計(jì)頁(yè)面,執(zhí)行放置-頁(yè)面符命令,...

      2.

      將光標(biāo)放到需要放置的位置單擊兩次,確定圖形形狀,此時(shí)初步畫出一個(gè)方塊電路。

      3.

      雙擊電路上面的名字可以彈出界面進(jìn)行更改,改動(dòng)一下,得到自己需要的名稱,便于后續(xù)區(qū)分。

      4.

      同樣,雙擊邊框,可以對(duì)其屬性進(jìn)行設(shè)置,如長(zhǎng)寬尺寸,邊框類型,填充顏色等信息。

      五、廚房電路設(shè)計(jì)

      廚房電路設(shè)計(jì)

      在家裝或者裝修中,廚房電路設(shè)計(jì)是一個(gè)非常重要的環(huán)節(jié)。電路設(shè)計(jì)合理與否,不僅關(guān)系到日常使用的便利性,更關(guān)系到安全性。本文將從以下幾個(gè)方面介紹廚房電路設(shè)計(jì)的注意事項(xiàng)。

      總體設(shè)計(jì)原則

      廚房電路設(shè)計(jì)需要遵循以下原則:

      1. 保證用電安全
      2. 保證用電合理
      3. 保證用電方便
      4. 保證用電美觀

      這些原則需要在具體設(shè)計(jì)中考慮到并體現(xiàn)出來(lái)。

      具體設(shè)計(jì)細(xì)節(jié)

      1: 廚房電器用電量估算

      在設(shè)計(jì)廚房電路之前,需要先估算廚房電器的用電量。根據(jù)廚房電器的功率和使用頻率,可以大致估算出每個(gè)電器的用電量。用電量的估算是電路設(shè)計(jì)的基礎(chǔ),只有準(zhǔn)確的估算才能保證后續(xù)的電路設(shè)計(jì)合理。

      2: 廚房電器用電位置規(guī)劃

      在估算出廚房電器的用電量后,需要規(guī)劃好每個(gè)電器的用電位置。不同電器的用電位置應(yīng)該分開(kāi)設(shè)計(jì),避免因?yàn)榧杏秒妼?dǎo)致電路過(guò)載。同時(shí),需要考慮到電器的使用頻率和使用場(chǎng)景,將常用的電器放在使用方便的位置,避免不必要的麻煩。

      3: 廚房插座數(shù)量規(guī)劃

      插座數(shù)量的規(guī)劃需要根據(jù)廚房電器的用電量和用電位置來(lái)確定。需要注意的是,插座數(shù)量不能太多也不能太少。太多的插座會(huì)影響美觀,太少的插座則會(huì)影響使用。一般來(lái)說(shuō),每個(gè)用電位置都需要有一個(gè)插座。

      4: 廚房電路容量規(guī)劃

      廚房電路容量的規(guī)劃需要根據(jù)廚房電器的用電量來(lái)確定。一般來(lái)說(shuō),廚房的總電路容量不應(yīng)該低于3kW。如果廚房電器的用電量很大,需要考慮分路供電。

      以上是廚房電路設(shè)計(jì)的幾個(gè)注意事項(xiàng),希望能夠?qū)Υ蠹矣兴鶐椭?/p>

      六、電路設(shè)計(jì)軟件哪個(gè)好用?

      國(guó)內(nèi)幾乎都是用這三個(gè)軟件畫原理圖和PCB:

      1. Altium Designer (Protel 99) 。界面很炫,板的3D效果不錯(cuò),然并卵。。估計(jì)學(xué)生及小公司用得多。

      2. Pads。也挺好用,界面沒(méi)Altium友好,但是很流暢,多層板換層高亮?xí)r從不會(huì)卡。中大型公司用得多。

      3. Cadence Orcad。在多層板,高速PCB設(shè)計(jì)及仿真上很牛叉,也是中大型公司用得多。初學(xué)的建議選第一個(gè),簡(jiǎn)單易學(xué)好上手,教程也多。特別是手工做板的時(shí)候,設(shè)置打印PCB各層很方便。

      七、集成電路設(shè)計(jì)考研?

      這個(gè)專業(yè)考研選擇還是挺多的,本專業(yè)有模擬集成電路設(shè)計(jì)方向、數(shù)字集成電路設(shè)計(jì)方向、射頻集成電路設(shè)計(jì)方向、混合信號(hào)集成電路設(shè)計(jì)方向、微電子器件方向、集成電路工藝方向、人工智能算法方向。此外電氣工程方向、電子方向、通信方向、軟件開(kāi)發(fā)、計(jì)算機(jī)、自動(dòng)化都可以跨考。

      八、eda分頻電路設(shè)計(jì)原理?

      所謂“分頻”,就是把輸入信號(hào)的頻率變成成倍數(shù)地低于輸入頻率的輸出信號(hào)。文獻(xiàn)資料上所謂用計(jì)數(shù)器的方法做“分頻器”的方法,只是眾多方法中的一種。它的原理是:把輸入的信號(hào)作為計(jì)數(shù)脈沖,由于計(jì)數(shù)器的輸出端口是按一定規(guī)律輸出脈沖的,所以對(duì)不同的端口輸出的信號(hào)脈沖,就可以看作是對(duì)輸入信號(hào)的”分頻“。至于分頻頻率是怎樣的,由選用的計(jì)數(shù)器所決定。

      如果是十進(jìn)制的計(jì)數(shù)器那就是十分頻,如果是二進(jìn)制的計(jì)數(shù)器那就是二分頻,還有四進(jìn)制、八進(jìn)制、十六進(jìn)制等等。以此類推。

      九、變送器電路設(shè)計(jì)

      變送器電路設(shè)計(jì)是工業(yè)自動(dòng)化領(lǐng)域中非常關(guān)鍵的一部分。變送器是將傳感器所感知到的物理量轉(zhuǎn)換成標(biāo)準(zhǔn)信號(hào)輸出,用來(lái)反映被測(cè)量物理量的狀態(tài)的裝置。在各種工業(yè)控制系統(tǒng)中,變送器起著至關(guān)重要的作用,因?yàn)樗鼈兡軌驅(qū)⒎请娦盘?hào)轉(zhuǎn)換成電信號(hào),實(shí)現(xiàn)傳感器和控制器之間的有效連接。

      變送器電路設(shè)計(jì)的重要性

      對(duì)于變送器電路設(shè)計(jì)來(lái)說(shuō),要充分考慮到工業(yè)環(huán)境下的各種因素以確保系統(tǒng)的穩(wěn)定性和可靠性。以下是變送器電路設(shè)計(jì)的幾個(gè)重要因素:

      1. 噪聲抑制:在工業(yè)環(huán)境中,噪聲干擾是不可避免的。良好的變送器電路設(shè)計(jì)應(yīng)該具備強(qiáng)大的噪聲抑制能力,以確保測(cè)量結(jié)果的準(zhǔn)確性。
      2. 線性度:變送器應(yīng)具備良好的線性度,即輸出信號(hào)應(yīng)與輸入信號(hào)成正比。這對(duì)于系統(tǒng)的精確度和可靠性至關(guān)重要。
      3. 溫度補(bǔ)償:工業(yè)環(huán)境中,溫度變化較大,因此變送器電路設(shè)計(jì)應(yīng)包含溫度補(bǔ)償電路,以確保系統(tǒng)在不同工作溫度下的準(zhǔn)確性。
      4. 功耗:變送器電路設(shè)計(jì)應(yīng)該盡可能低功耗,以延長(zhǎng)電池壽命或減少能源消耗。
      5. 抗干擾能力:工業(yè)環(huán)境中存在大量的電磁干擾源,變送器電路設(shè)計(jì)應(yīng)具備良好的抗干擾能力,以避免干擾信號(hào)對(duì)信號(hào)傳輸和測(cè)量結(jié)果的影響。

      變送器電路設(shè)計(jì)的基本原則

      變送器電路設(shè)計(jì)需要遵循一些基本原則,以確保設(shè)計(jì)的穩(wěn)定性和可靠性:

      • 選擇合適的傳感器:傳感器的選擇對(duì)于變送器電路設(shè)計(jì)至關(guān)重要。要根據(jù)被測(cè)量的物理量和工作環(huán)境的需求選擇合適的傳感器。
      • 合理的功率供應(yīng):變送器電路設(shè)計(jì)應(yīng)確保提供穩(wěn)定可靠的功率供應(yīng),以確保系統(tǒng)正常運(yùn)行。
      • 合理的濾波設(shè)計(jì):噪聲濾波是變送器電路設(shè)計(jì)中的重要一環(huán)。合理的濾波設(shè)計(jì)可以有效減少噪聲干擾。
      • 采用合適的放大電路:放大電路在變送器電路設(shè)計(jì)中起著關(guān)鍵作用。選擇合適的放大電路可以提高信號(hào)的準(zhǔn)確度和穩(wěn)定性。
      • 合理的輸出電路設(shè)計(jì):輸出電路設(shè)計(jì)應(yīng)根據(jù)具體需求選擇合適的輸出方式,如電流輸出或電壓輸出。

      變送器電路設(shè)計(jì)的實(shí)際應(yīng)用

      變送器電路設(shè)計(jì)廣泛應(yīng)用于各種工業(yè)自動(dòng)化系統(tǒng)中,如壓力變送器、溫度變送器、流量變送器等。以溫度變送器為例,它將溫度傳感器所感知到的溫度轉(zhuǎn)換成對(duì)應(yīng)的電信號(hào)輸出。這些電信號(hào)可以通過(guò)工業(yè)控制系統(tǒng)進(jìn)行采集、傳輸和處理,實(shí)現(xiàn)溫度數(shù)據(jù)的監(jiān)測(cè)和控制。

      在變送器電路設(shè)計(jì)中,還需要考慮到通信協(xié)議的選擇。現(xiàn)代工業(yè)控制系統(tǒng)多使用數(shù)字通信協(xié)議進(jìn)行數(shù)據(jù)傳輸,如HART、FOUNDATION Fieldbus和Profibus等。變送器電路設(shè)計(jì)應(yīng)根據(jù)具體應(yīng)用需求選擇適合的通信協(xié)議,并設(shè)計(jì)相應(yīng)的通信接口。

      變送器電路設(shè)計(jì)對(duì)于工業(yè)自動(dòng)化領(lǐng)域具有重要意義。通過(guò)合理、穩(wěn)定、可靠的電路設(shè)計(jì),可以提高控制系統(tǒng)的性能和效率,同時(shí)降低故障率和維護(hù)成本。因此,對(duì)于工程師而言,掌握變送器電路設(shè)計(jì)的基本原理和技術(shù)是至關(guān)重要的。

      希望本文對(duì)讀者了解變送器電路設(shè)計(jì)有所幫助,同時(shí)也希望讀者能夠在實(shí)際應(yīng)用中靈活運(yùn)用這些原理和技術(shù),提高工業(yè)自動(dòng)化系統(tǒng)的性能和可靠性。

      十、mahout面試題?

      之前看了Mahout官方示例 20news 的調(diào)用實(shí)現(xiàn);于是想根據(jù)示例的流程實(shí)現(xiàn)其他例子。網(wǎng)上看到了一個(gè)關(guān)于天氣適不適合打羽毛球的例子。

      訓(xùn)練數(shù)據(jù):

      Day Outlook Temperature Humidity Wind PlayTennis

      D1 Sunny Hot High Weak No

      D2 Sunny Hot High Strong No

      D3 Overcast Hot High Weak Yes

      D4 Rain Mild High Weak Yes

      D5 Rain Cool Normal Weak Yes

      D6 Rain Cool Normal Strong No

      D7 Overcast Cool Normal Strong Yes

      D8 Sunny Mild High Weak No

      D9 Sunny Cool Normal Weak Yes

      D10 Rain Mild Normal Weak Yes

      D11 Sunny Mild Normal Strong Yes

      D12 Overcast Mild High Strong Yes

      D13 Overcast Hot Normal Weak Yes

      D14 Rain Mild High Strong No

      檢測(cè)數(shù)據(jù):

      sunny,hot,high,weak

      結(jié)果:

      Yes=》 0.007039

      No=》 0.027418

      于是使用Java代碼調(diào)用Mahout的工具類實(shí)現(xiàn)分類。

      基本思想:

      1. 構(gòu)造分類數(shù)據(jù)。

      2. 使用Mahout工具類進(jìn)行訓(xùn)練,得到訓(xùn)練模型。

      3。將要檢測(cè)數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。

      4. 分類器對(duì)vector數(shù)據(jù)進(jìn)行分類。

      接下來(lái)貼下我的代碼實(shí)現(xiàn)=》

      1. 構(gòu)造分類數(shù)據(jù):

      在hdfs主要?jiǎng)?chuàng)建一個(gè)文件夾路徑 /zhoujainfeng/playtennis/input 并將分類文件夾 no 和 yes 的數(shù)據(jù)傳到hdfs上面。

      數(shù)據(jù)文件格式,如D1文件內(nèi)容: Sunny Hot High Weak

      2. 使用Mahout工具類進(jìn)行訓(xùn)練,得到訓(xùn)練模型。

      3。將要檢測(cè)數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。

      4. 分類器對(duì)vector數(shù)據(jù)進(jìn)行分類。

      這三步,代碼我就一次全貼出來(lái);主要是兩個(gè)類 PlayTennis1 和 BayesCheckData = =》

      package myTesting.bayes;

      import org.apache.hadoop.conf.Configuration;

      import org.apache.hadoop.fs.FileSystem;

      import org.apache.hadoop.fs.Path;

      import org.apache.hadoop.util.ToolRunner;

      import org.apache.mahout.classifier.naivebayes.training.TrainNaiveBayesJob;

      import org.apache.mahout.text.SequenceFilesFromDirectory;

      import org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles;

      public class PlayTennis1 {

      private static final String WORK_DIR = "hdfs://192.168.9.72:9000/zhoujianfeng/playtennis";

      /*

      * 測(cè)試代碼

      */

      public static void main(String[] args) {

      //將訓(xùn)練數(shù)據(jù)轉(zhuǎn)換成 vector數(shù)據(jù)

      makeTrainVector();

      //產(chǎn)生訓(xùn)練模型

      makeModel(false);

      //測(cè)試檢測(cè)數(shù)據(jù)

      BayesCheckData.printResult();

      }

      public static void makeCheckVector(){

      //將測(cè)試數(shù)據(jù)轉(zhuǎn)換成序列化文件

      try {

      Configuration conf = new Configuration();

      conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));

      String input = WORK_DIR+Path.SEPARATOR+"testinput";

      String output = WORK_DIR+Path.SEPARATOR+"tennis-test-seq";

      Path in = new Path(input);

      Path out = new Path(output);

      FileSystem fs = FileSystem.get(conf);

      if(fs.exists(in)){

      if(fs.exists(out)){

      //boolean參數(shù)是,是否遞歸刪除的意思

      fs.delete(out, true);

      }

      SequenceFilesFromDirectory sffd = new SequenceFilesFromDirectory();

      String[] params = new String[]{"-i",input,"-o",output,"-ow"};

      ToolRunner.run(sffd, params);

      }

      } catch (Exception e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      System.out.println("文件序列化失敗!");

      System.exit(1);

      }

      //將序列化文件轉(zhuǎn)換成向量文件

      try {

      Configuration conf = new Configuration();

      conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));

      String input = WORK_DIR+Path.SEPARATOR+"tennis-test-seq";

      String output = WORK_DIR+Path.SEPARATOR+"tennis-test-vectors";

      Path in = new Path(input);

      Path out = new Path(output);

      FileSystem fs = FileSystem.get(conf);

      if(fs.exists(in)){

      if(fs.exists(out)){

      //boolean參數(shù)是,是否遞歸刪除的意思

      fs.delete(out, true);

      }

      SparseVectorsFromSequenceFiles svfsf = new SparseVectorsFromSequenceFiles();

      String[] params = new String[]{"-i",input,"-o",output,"-lnorm","-nv","-wt","tfidf"};

      ToolRunner.run(svfsf, params);

      }

      } catch (Exception e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      System.out.println("序列化文件轉(zhuǎn)換成向量失敗!");

      System.out.println(2);

      }

      }

      public static void makeTrainVector(){

      //將測(cè)試數(shù)據(jù)轉(zhuǎn)換成序列化文件

      try {

      Configuration conf = new Configuration();

      conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));

      String input = WORK_DIR+Path.SEPARATOR+"input";

      String output = WORK_DIR+Path.SEPARATOR+"tennis-seq";

      Path in = new Path(input);

      Path out = new Path(output);

      FileSystem fs = FileSystem.get(conf);

      if(fs.exists(in)){

      if(fs.exists(out)){

      //boolean參數(shù)是,是否遞歸刪除的意思

      fs.delete(out, true);

      }

      SequenceFilesFromDirectory sffd = new SequenceFilesFromDirectory();

      String[] params = new String[]{"-i",input,"-o",output,"-ow"};

      ToolRunner.run(sffd, params);

      }

      } catch (Exception e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      System.out.println("文件序列化失敗!");

      System.exit(1);

      }

      //將序列化文件轉(zhuǎn)換成向量文件

      try {

      Configuration conf = new Configuration();

      conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));

      String input = WORK_DIR+Path.SEPARATOR+"tennis-seq";

      String output = WORK_DIR+Path.SEPARATOR+"tennis-vectors";

      Path in = new Path(input);

      Path out = new Path(output);

      FileSystem fs = FileSystem.get(conf);

      if(fs.exists(in)){

      if(fs.exists(out)){

      //boolean參數(shù)是,是否遞歸刪除的意思

      fs.delete(out, true);

      }

      SparseVectorsFromSequenceFiles svfsf = new SparseVectorsFromSequenceFiles();

      String[] params = new String[]{"-i",input,"-o",output,"-lnorm","-nv","-wt","tfidf"};

      ToolRunner.run(svfsf, params);

      }

      } catch (Exception e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      System.out.println("序列化文件轉(zhuǎn)換成向量失敗!");

      System.out.println(2);

      }

      }

      public static void makeModel(boolean completelyNB){

      try {

      Configuration conf = new Configuration();

      conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));

      String input = WORK_DIR+Path.SEPARATOR+"tennis-vectors"+Path.SEPARATOR+"tfidf-vectors";

      String model = WORK_DIR+Path.SEPARATOR+"model";

      String labelindex = WORK_DIR+Path.SEPARATOR+"labelindex";

      Path in = new Path(input);

      Path out = new Path(model);

      Path label = new Path(labelindex);

      FileSystem fs = FileSystem.get(conf);

      if(fs.exists(in)){

      if(fs.exists(out)){

      //boolean參數(shù)是,是否遞歸刪除的意思

      fs.delete(out, true);

      }

      if(fs.exists(label)){

      //boolean參數(shù)是,是否遞歸刪除的意思

      fs.delete(label, true);

      }

      TrainNaiveBayesJob tnbj = new TrainNaiveBayesJob();

      String[] params =null;

      if(completelyNB){

      params = new String[]{"-i",input,"-el","-o",model,"-li",labelindex,"-ow","-c"};

      }else{

      params = new String[]{"-i",input,"-el","-o",model,"-li",labelindex,"-ow"};

      }

      ToolRunner.run(tnbj, params);

      }

      } catch (Exception e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      System.out.println("生成訓(xùn)練模型失敗!");

      System.exit(3);

      }

      }

      }

      package myTesting.bayes;

      import java.io.IOException;

      import java.util.HashMap;

      import java.util.Map;

      import org.apache.commons.lang.StringUtils;

      import org.apache.hadoop.conf.Configuration;

      import org.apache.hadoop.fs.Path;

      import org.apache.hadoop.fs.PathFilter;

      import org.apache.hadoop.io.IntWritable;

      import org.apache.hadoop.io.LongWritable;

      import org.apache.hadoop.io.Text;

      import org.apache.mahout.classifier.naivebayes.BayesUtils;

      import org.apache.mahout.classifier.naivebayes.NaiveBayesModel;

      import org.apache.mahout.classifier.naivebayes.StandardNaiveBayesClassifier;

      import org.apache.mahout.common.Pair;

      import org.apache.mahout.common.iterator.sequencefile.PathType;

      import org.apache.mahout.common.iterator.sequencefile.SequenceFileDirIterable;

      import org.apache.mahout.math.RandomAccessSparseVector;

      import org.apache.mahout.math.Vector;

      import org.apache.mahout.math.Vector.Element;

      import org.apache.mahout.vectorizer.TFIDF;

      import com.google.common.collect.ConcurrentHashMultiset;

      import com.google.common.collect.Multiset;

      public class BayesCheckData {

      private static StandardNaiveBayesClassifier classifier;

      private static Map<String, Integer> dictionary;

      private static Map<Integer, Long> documentFrequency;

      private static Map<Integer, String> labelIndex;

      public void init(Configuration conf){

      try {

      String modelPath = "/zhoujianfeng/playtennis/model";

      String dictionaryPath = "/zhoujianfeng/playtennis/tennis-vectors/dictionary.file-0";

      String documentFrequencyPath = "/zhoujianfeng/playtennis/tennis-vectors/df-count";

      String labelIndexPath = "/zhoujianfeng/playtennis/labelindex";

      dictionary = readDictionnary(conf, new Path(dictionaryPath));

      documentFrequency = readDocumentFrequency(conf, new Path(documentFrequencyPath));

      labelIndex = BayesUtils.readLabelIndex(conf, new Path(labelIndexPath));

      NaiveBayesModel model = NaiveBayesModel.materialize(new Path(modelPath), conf);

      classifier = new StandardNaiveBayesClassifier(model);

      } catch (IOException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      System.out.println("檢測(cè)數(shù)據(jù)構(gòu)造成vectors初始化時(shí)報(bào)錯(cuò)。。。。");

      System.exit(4);

      }

      }

      /**

      * 加載字典文件,Key: TermValue; Value:TermID

      * @param conf

      * @param dictionnaryDir

      * @return

      */

      private static Map<String, Integer> readDictionnary(Configuration conf, Path dictionnaryDir) {

      Map<String, Integer> dictionnary = new HashMap<String, Integer>();

      PathFilter filter = new PathFilter() {

      @Override

      public boolean accept(Path path) {

      String name = path.getName();

      return name.startsWith("dictionary.file");

      }

      };

      for (Pair<Text, IntWritable> pair : new SequenceFileDirIterable<Text, IntWritable>(dictionnaryDir, PathType.LIST, filter, conf)) {

      dictionnary.put(pair.getFirst().toString(), pair.getSecond().get());

      }

      return dictionnary;

      }

      /**

      * 加載df-count目錄下TermDoc頻率文件,Key: TermID; Value:DocFreq

      * @param conf

      * @param dictionnaryDir

      * @return

      */

      private static Map<Integer, Long> readDocumentFrequency(Configuration conf, Path documentFrequencyDir) {

      Map<Integer, Long> documentFrequency = new HashMap<Integer, Long>();

      PathFilter filter = new PathFilter() {

      @Override

      public boolean accept(Path path) {

      return path.getName().startsWith("part-r");

      }

      };

      for (Pair<IntWritable, LongWritable> pair : new SequenceFileDirIterable<IntWritable, LongWritable>(documentFrequencyDir, PathType.LIST, filter, conf)) {

      documentFrequency.put(pair.getFirst().get(), pair.getSecond().get());

      }

      return documentFrequency;

      }

      public static String getCheckResult(){

      Configuration conf = new Configuration();

      conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));

      String classify = "NaN";

      BayesCheckData cdv = new BayesCheckData();

      cdv.init(conf);

      System.out.println("init done...............");

      Vector vector = new RandomAccessSparseVector(10000);

      TFIDF tfidf = new TFIDF();

      //sunny,hot,high,weak

      Multiset<String> words = ConcurrentHashMultiset.create();

      words.add("sunny",1);

      words.add("hot",1);

      words.add("high",1);

      words.add("weak",1);

      int documentCount = documentFrequency.get(-1).intValue(); // key=-1時(shí)表示總文檔數(shù)

      for (Multiset.Entry<String> entry : words.entrySet()) {

      String word = entry.getElement();

      int count = entry.getCount();

      Integer wordId = dictionary.get(word); // 需要從dictionary.file-0文件(tf-vector)下得到wordID,

      if (StringUtils.isEmpty(wordId.toString())){

      continue;

      }

      if (documentFrequency.get(wordId) == null){

      continue;

      }

      Long freq = documentFrequency.get(wordId);

      double tfIdfValue = tfidf.calculate(count, freq.intValue(), 1, documentCount);

      vector.setQuick(wordId, tfIdfValue);

      }

      // 利用貝葉斯算法開(kāi)始分類,并提取得分最好的分類label

      Vector resultVector = classifier.classifyFull(vector);

      double bestScore = -Double.MAX_VALUE;

      int bestCategoryId = -1;

      for(Element element: resultVector.all()) {

      int categoryId = element.index();

      double score = element.get();

      System.out.println("categoryId:"+categoryId+" score:"+score);

      if (score > bestScore) {

      bestScore = score;

      bestCategoryId = categoryId;

      }

      }

      classify = labelIndex.get(bestCategoryId)+"(categoryId="+bestCategoryId+")";

      return classify;

      }

      public static void printResult(){

      System.out.println("檢測(cè)所屬類別是:"+getCheckResult());

      }

      }

      相關(guān)資訊
      熱門頻道

      Copyright © 2024 招聘街 滇ICP備2024020316號(hào)-38

      国内精品久久久久_亚洲区手机在线中文无码播放_国内精品久久久久影院一蜜桃_日韩内射激情视频在线播放免费

        常山县| 公主岭市| 思茅市| 于都县| 萨嘎县| 格尔木市| 旬邑县| 岗巴县| 文化| 丹棱县| 松阳县| 武安市| 佛冈县| 育儿| 红原县| 香格里拉县| 凤凰县| 荃湾区| 阿图什市| 阿瓦提县| 乌拉特中旗| 淄博市| 灌云县| 姜堰市| 布尔津县| 宜宾县| 长兴县| 璧山县| 宝应县| 永康市| 天门市| 左云县| 柳江县| 新宾| 阜新| 临夏县| 五家渠市| 嘉义县| 大冶市| 衡阳市| 云安县|