This paper is a partial translation and collation of the original English version of SQL Server data Mining Managed Plug-In algorithms tutorial, mainly describing the basic extension methods and development process of SSAS data mining algorithms. The content of this article is only part of the original text, if you want to know more information can download the original. The original English text is downloaded in the appendix of this article.
SSAS provides us with nine data mining algorithms, but in the application we need to design the appropriate algorithm based on the actual problem, this time we need to extend SSAS, so that it can apply more algorithms, SSAS have better scalability, it provides a complete mechanism for expansion, You can use your own algorithm in SSAS as long as you inherit some classes and register them in the appropriate way. Below I will use several articles to explain how to develop the SSAS algorithm plug-in, respectively. This article introduces the algorithm plug-in development method is based on managed code, is developed in C # (algorithm Plug-ins can also be developed in C + +, and SQLSERVER2005 case with C + + version of the code stub). The whole process is up to six steps. Before you start development, you need to do some preparation to download a COM component written in C + +, called Dmpluginwrapper (available by downloading the attachments included with this article), as the middle tier of the SSAS and algorithmic Plug-ins, Used to process the interaction between SSAS and Algorithmic Plug-ins, and to encapsulate the parameters from SSAs to algorithmic plug-ins and the processing results from the algorithm plug-in to SSAS. The relationship between Dmpluginwrapper, SSAS, and algorithmic Plug-ins can be described in the following illustration.
Relationship between Chart 1:dmpluginwrapper, SSAS, and algorithmic Plug-ins
The following starts the project to create an algorithm extension.
Start by creating a new Class Library project (named Algorithmplugin) that references the Dmpluginwrapper project just now to the new Algorithmplugin Class library project. You can choose to sign the Class Library project as an assembly so that it can be registered in the GAC. Also, add a build script for Dmpluginwrapper to register the assembly with the GAC, as follows (depending on the machine's specific settings):
"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe" $(TargetPath)
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /u $(TargetName)
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /if $(TargetPath)
If the first line of script does not work correctly, the algorithm plug-in cannot be identified by the SQL Server Analysis servers. The other two lines of script are registering the algorithmic assembly with the GAC.
The next few steps are primarily to inherit the work of some base classes, including the Algorithmmetadatabase class, the Algorithmbase class, and the Icaseprocessor interface and the Algorithmnavigationbase class. First create a new class file in Algorithmplugin and name it metadata, adding ComVisible, Miningalgorithmclass (typeof), and GUID attributes for this class ( The algorithm is the algorithm class to be created below) and specifies a GUID encoding for the GUID property. This class will inherit from the Algorithmmetadatabase class. The thing to do now is to override the base class method. Here are all the methods that need to be overridden (for simpler implementations written in a table):
Method name |
Implementation (Reference) |
Note |
Getservicename |
return "MyFirstAlgorithmPlugin" |
The return value of this method cannot contain a space character |
Getservicedescription |
return "Sample Algorithm Plugin"; |
|
Getservicetype |
PlugInServiceType.ServiceTypeOther; |
|
Getviewertype |
return string.Empty |
|
Getscaling |
return MiningScaling.Medium; |
Used to specify the size of the algorithm, which is not used by the server but is displayed in the pattern rowset, providing some relevant information about the algorithm to the user. |
Gettrainingcomplexity |
return MiningTrainingComplexity.Low |
Used to specify the complexity of the algorithm training application, which is not used by the server but is displayed in the pattern rowset, providing some information about the algorithm to the user. |
Getpredictioncomplexity |
return MiningPredictionComplexity.Low |
Used to specify predictive complexity, which is not used by the server but is displayed in the pattern rowset, providing some information about the algorithm to the user. |
Getsupportsdmdimensions |
retrun false; |
|
Getsupportsdrillthrough |
return false; |
Specifies whether this algorithm supports drill through capabilities. |
Getdrillthroughmustincludechildren |
return false; |
|
Getcaseidmodeled |
return false; |
|
Getmarginalrequirements |
return MarginalRequirements.AllStats |
|
Getparameterscollection |
return null; |
Algorithm parameters, because the example in this article has no parameters, so return null here. |
Getsupinputcontenttypes |
MiningColumnContent[] arInputContentTypes = new MiningColumnContent[] { MiningColumnContent.Discrete, MiningColumnContent.Continuous, MiningColumnContent.Discretized, MiningColumnContent.NestedTable, MiningColumnContent.Key }; return arInputContentTypes; |
Specifies the data type of the input properties supported by the algorithm, such as continuous, discrete, and so on. |
Getsuppredictcontenttypes |
MiningColumnContent[] arPredictContentTypes = new MiningColumnContent[] { MiningColumnContent.Discrete, MiningColumnContent.Continuous, MiningColumnContent.Discretized, MiningColumnContent.NestedTable, MiningColumnContent.Key }; return arPredictContentTypes; |
Similar to the previous method, this is the type of data supported by the specified forecast attribute. |
Getsupportedstandardfunctions |
supportedfunction[] Arfuncs = new supportedfunction[] { Supportedfunction.predictsupport, Supportedfunction.predicthistogram, Supportedfunction.predictprobability, supportedfunction.predictadjustedprobability, Supportedfunction.predictassociation, Supportedfunction.predictstddev, Supportedfunction.predictvariance, Supportedfunction.rangemax, Supportedfunction.rangemid, Supportedfunction.rangemin, supportedfunction.dadjustedprobability, Supportedfunction.dprobability, Supportedfunction.dstddev, Supportedfunction.dsupport, Supportedfunction.dvariance, //content-related functions Supportedfunction.isdescendent, Supportedfunction.predictnodeid, Supportedfunction.isinnode, Supportedfunction.dnodeid, } ; Return Arfuncs |
Specifies the functions supported by DMX. |
Createalgorithm |
return new Algorithm(); |
Returns the algorithm instance, algorithm is the next class to be created. |